diff options
author | CoprDistGit <infra@openeuler.org> | 2023-05-31 08:18:55 +0000 |
---|---|---|
committer | CoprDistGit <infra@openeuler.org> | 2023-05-31 08:18:55 +0000 |
commit | 7ed55700f672b292eff175105176cf0b1babf0fb (patch) | |
tree | c805ad2c87973343788751372eb14004ba118057 | |
parent | 62e0094a492ec3bdada1b6d4da5215b94ea5459e (diff) |
automatic import of python-flask-google-cloud-logger
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | python-flask-google-cloud-logger.spec | 359 | ||||
-rw-r--r-- | sources | 1 |
3 files changed, 361 insertions, 0 deletions
@@ -0,0 +1 @@ +/flask_google_cloud_logger-0.2.1.tar.gz diff --git a/python-flask-google-cloud-logger.spec b/python-flask-google-cloud-logger.spec new file mode 100644 index 0000000..eda7489 --- /dev/null +++ b/python-flask-google-cloud-logger.spec @@ -0,0 +1,359 @@ +%global _empty_manifest_terminate_build 0 +Name: python-flask-google-cloud-logger +Version: 0.2.1 +Release: 1 +Summary: Google Cloud Log Formatter for Flask +License: MIT +URL: http://github.com/rai200890/flask_google_cloud_logger +Source0: https://mirrors.nju.edu.cn/pypi/web/packages/57/2a/2e47d97abda2297cd0bff8f96a7aa52f79b05de7b82800abde4f5249be8b/flask_google_cloud_logger-0.2.1.tar.gz +BuildArch: noarch + +Requires: python3-google-cloud-logger +Requires: python3-flask + +%description +# flask_google_cloud_logger +[](https://circleci.com/gh/rai200890/flask_google_cloud_logger) +[](https://badge.fury.io/py/flask-google-cloud-logger) +[](https://codeclimate.com/github/rai200890/flask_google_cloud_logger/maintainability) +[](https://codeclimate.com/github/rai200890/flask_google_cloud_logger/test_coverage) + +Flask extension to format logs according to Google Cloud v2 Specification + +Python log formatter for Google Cloud according to [v2 specification](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry) using [python-json-logger](https://github.com/madzak/python-json-logger) formatter + +Inspired by Elixir's [logger_json](https://github.com/Nebo15/logger_json) + +## Instalation + +### Pipenv + +``` + pipenv install flask_google_cloud_logger +``` + +### Pip + +``` + pip install flask_google_cloud_logger +``` + +## Usage + +```python +import logging +from logging import config + +from flask import Flask, request, g +from flask_google_cloud_logger import FlaskGoogleCloudLogger + +LOG_CONFIG = { + "version": 1, + "formatters": { + "json": { + "()": "flask_google_cloud_logger.FlaskGoogleCloudFormatter", + "application_info": { + "type": "python-application", + "application_name": "Example Application" + }, + "format": "[%(asctime)s] %(levelname)s in %(module)s: %(message)s" + } + }, + "handlers": { + "json": { + "class": "logging.StreamHandler", + "formatter": "json" + } + }, + "loggers": { + "root": { + "level": "INFO", + "handlers": ["json"] + }, + "werkzeug": { + "level": "WARN", # Disable werkzeug hardcoded logger + "handlers": ["json"] + } + } +} + +config.dictConfig(LOG_CONFIG) # load log config from dict +logger = logging.getLogger("root") # get root logger instance +app = Flask("test_app") +FlaskGoogleCloudLogger(app) + + +@app.route("/") +def hello_world(): + return "Hello, World!" + + +@app.teardown_request #log request and response info after extension's callbacks +def log_request_time(_exception): + logger.info( + f"{request.method} {request.path} - Sent {g.response.status_code}" + + " in {g.request_time:.5f}ms") + +``` + +Example output: + +```json +{"timestamp": "2018-11-04T22:07:42.687000Z", "severity": "INFO", "message": "GET / - Sent 200 in {g.request_time:.5f}ms", "labels": {"type": "python-application", "application_name": "Example Application", "client": {"user_agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.75 Safari/537.36", "ip": "127.0.0.1", "version": null}, "connection": {"method": "GET", "path": "/", "request_id": "afc4c6d5-5f30-4f02-b66a-e97e87841073", "status": 200}, "latency": 0.13828277587890625}, "metadata": {"userLabels": {}}, "sourceLocation": {"file": "test_app.py", "line": 52, "function": "log_request_time"}} +``` + +## Credits + +Thanks [@thulio](https://github.com/thulio), [@robsonpeixoto](https://github.com/robsonpeixoto), [@ramondelemos](https://github.com/ramondelemos) + + + + +%package -n python3-flask-google-cloud-logger +Summary: Google Cloud Log Formatter for Flask +Provides: python-flask-google-cloud-logger +BuildRequires: python3-devel +BuildRequires: python3-setuptools +BuildRequires: python3-pip +%description -n python3-flask-google-cloud-logger +# flask_google_cloud_logger +[](https://circleci.com/gh/rai200890/flask_google_cloud_logger) +[](https://badge.fury.io/py/flask-google-cloud-logger) +[](https://codeclimate.com/github/rai200890/flask_google_cloud_logger/maintainability) +[](https://codeclimate.com/github/rai200890/flask_google_cloud_logger/test_coverage) + +Flask extension to format logs according to Google Cloud v2 Specification + +Python log formatter for Google Cloud according to [v2 specification](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry) using [python-json-logger](https://github.com/madzak/python-json-logger) formatter + +Inspired by Elixir's [logger_json](https://github.com/Nebo15/logger_json) + +## Instalation + +### Pipenv + +``` + pipenv install flask_google_cloud_logger +``` + +### Pip + +``` + pip install flask_google_cloud_logger +``` + +## Usage + +```python +import logging +from logging import config + +from flask import Flask, request, g +from flask_google_cloud_logger import FlaskGoogleCloudLogger + +LOG_CONFIG = { + "version": 1, + "formatters": { + "json": { + "()": "flask_google_cloud_logger.FlaskGoogleCloudFormatter", + "application_info": { + "type": "python-application", + "application_name": "Example Application" + }, + "format": "[%(asctime)s] %(levelname)s in %(module)s: %(message)s" + } + }, + "handlers": { + "json": { + "class": "logging.StreamHandler", + "formatter": "json" + } + }, + "loggers": { + "root": { + "level": "INFO", + "handlers": ["json"] + }, + "werkzeug": { + "level": "WARN", # Disable werkzeug hardcoded logger + "handlers": ["json"] + } + } +} + +config.dictConfig(LOG_CONFIG) # load log config from dict +logger = logging.getLogger("root") # get root logger instance +app = Flask("test_app") +FlaskGoogleCloudLogger(app) + + +@app.route("/") +def hello_world(): + return "Hello, World!" + + +@app.teardown_request #log request and response info after extension's callbacks +def log_request_time(_exception): + logger.info( + f"{request.method} {request.path} - Sent {g.response.status_code}" + + " in {g.request_time:.5f}ms") + +``` + +Example output: + +```json +{"timestamp": "2018-11-04T22:07:42.687000Z", "severity": "INFO", "message": "GET / - Sent 200 in {g.request_time:.5f}ms", "labels": {"type": "python-application", "application_name": "Example Application", "client": {"user_agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.75 Safari/537.36", "ip": "127.0.0.1", "version": null}, "connection": {"method": "GET", "path": "/", "request_id": "afc4c6d5-5f30-4f02-b66a-e97e87841073", "status": 200}, "latency": 0.13828277587890625}, "metadata": {"userLabels": {}}, "sourceLocation": {"file": "test_app.py", "line": 52, "function": "log_request_time"}} +``` + +## Credits + +Thanks [@thulio](https://github.com/thulio), [@robsonpeixoto](https://github.com/robsonpeixoto), [@ramondelemos](https://github.com/ramondelemos) + + + + +%package help +Summary: Development documents and examples for flask-google-cloud-logger +Provides: python3-flask-google-cloud-logger-doc +%description help +# flask_google_cloud_logger +[](https://circleci.com/gh/rai200890/flask_google_cloud_logger) +[](https://badge.fury.io/py/flask-google-cloud-logger) +[](https://codeclimate.com/github/rai200890/flask_google_cloud_logger/maintainability) +[](https://codeclimate.com/github/rai200890/flask_google_cloud_logger/test_coverage) + +Flask extension to format logs according to Google Cloud v2 Specification + +Python log formatter for Google Cloud according to [v2 specification](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry) using [python-json-logger](https://github.com/madzak/python-json-logger) formatter + +Inspired by Elixir's [logger_json](https://github.com/Nebo15/logger_json) + +## Instalation + +### Pipenv + +``` + pipenv install flask_google_cloud_logger +``` + +### Pip + +``` + pip install flask_google_cloud_logger +``` + +## Usage + +```python +import logging +from logging import config + +from flask import Flask, request, g +from flask_google_cloud_logger import FlaskGoogleCloudLogger + +LOG_CONFIG = { + "version": 1, + "formatters": { + "json": { + "()": "flask_google_cloud_logger.FlaskGoogleCloudFormatter", + "application_info": { + "type": "python-application", + "application_name": "Example Application" + }, + "format": "[%(asctime)s] %(levelname)s in %(module)s: %(message)s" + } + }, + "handlers": { + "json": { + "class": "logging.StreamHandler", + "formatter": "json" + } + }, + "loggers": { + "root": { + "level": "INFO", + "handlers": ["json"] + }, + "werkzeug": { + "level": "WARN", # Disable werkzeug hardcoded logger + "handlers": ["json"] + } + } +} + +config.dictConfig(LOG_CONFIG) # load log config from dict +logger = logging.getLogger("root") # get root logger instance +app = Flask("test_app") +FlaskGoogleCloudLogger(app) + + +@app.route("/") +def hello_world(): + return "Hello, World!" + + +@app.teardown_request #log request and response info after extension's callbacks +def log_request_time(_exception): + logger.info( + f"{request.method} {request.path} - Sent {g.response.status_code}" + + " in {g.request_time:.5f}ms") + +``` + +Example output: + +```json +{"timestamp": "2018-11-04T22:07:42.687000Z", "severity": "INFO", "message": "GET / - Sent 200 in {g.request_time:.5f}ms", "labels": {"type": "python-application", "application_name": "Example Application", "client": {"user_agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.75 Safari/537.36", "ip": "127.0.0.1", "version": null}, "connection": {"method": "GET", "path": "/", "request_id": "afc4c6d5-5f30-4f02-b66a-e97e87841073", "status": 200}, "latency": 0.13828277587890625}, "metadata": {"userLabels": {}}, "sourceLocation": {"file": "test_app.py", "line": 52, "function": "log_request_time"}} +``` + +## Credits + +Thanks [@thulio](https://github.com/thulio), [@robsonpeixoto](https://github.com/robsonpeixoto), [@ramondelemos](https://github.com/ramondelemos) + + + + +%prep +%autosetup -n flask-google-cloud-logger-0.2.1 + +%build +%py3_build + +%install +%py3_install +install -d -m755 %{buildroot}/%{_pkgdocdir} +if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi +if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi +if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi +if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi +pushd %{buildroot} +if [ -d usr/lib ]; then + find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/lib64 ]; then + find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/bin ]; then + find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/sbin ]; then + find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst +fi +touch doclist.lst +if [ -d usr/share/man ]; then + find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst +fi +popd +mv %{buildroot}/filelist.lst . +mv %{buildroot}/doclist.lst . + +%files -n python3-flask-google-cloud-logger -f filelist.lst +%dir %{python3_sitelib}/* + +%files help -f doclist.lst +%{_docdir}/* + +%changelog +* Wed May 31 2023 Python_Bot <Python_Bot@openeuler.org> - 0.2.1-1 +- Package Spec generated @@ -0,0 +1 @@ +87431de8b0f13ca1c45d23253f9e2a0e flask_google_cloud_logger-0.2.1.tar.gz |