{"id":17477939,"url":"https://github.com/rai200890/flask_google_cloud_logger","last_synced_at":"2025-04-22T11:24:07.085Z","repository":{"id":50200480,"uuid":"154046655","full_name":"rai200890/flask_google_cloud_logger","owner":"rai200890","description":"Flask extension to format logs according to Google Cloud v2 Specification","archived":false,"fork":false,"pushed_at":"2021-06-01T22:58:48.000Z","size":103,"stargazers_count":3,"open_issues_count":7,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-18T23:20:02.373Z","etag":null,"topics":["flask","google-cloud-logging","logging","python3"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rai200890.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-21T19:54:47.000Z","updated_at":"2023-02-07T17:05:26.000Z","dependencies_parsed_at":"2022-09-05T15:21:42.296Z","dependency_job_id":null,"html_url":"https://github.com/rai200890/flask_google_cloud_logger","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rai200890%2Fflask_google_cloud_logger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rai200890%2Fflask_google_cloud_logger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rai200890%2Fflask_google_cloud_logger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rai200890%2Fflask_google_cloud_logger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rai200890","download_url":"https://codeload.github.com/rai200890/flask_google_cloud_logger/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250229558,"owners_count":21396129,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["flask","google-cloud-logging","logging","python3"],"created_at":"2024-10-18T20:10:15.702Z","updated_at":"2025-04-22T11:24:07.056Z","avatar_url":"https://github.com/rai200890.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# flask_google_cloud_logger\n[![CircleCI](https://circleci.com/gh/rai200890/flask_google_cloud_logger.svg?style=svg\u0026circle-token=3b2eb197f30dc714a6ba81167ddcf4e10a8c92a6)](https://circleci.com/gh/rai200890/flask_google_cloud_logger)\n[![PyPI version](https://badge.fury.io/py/flask-google-cloud-logger.svg)](https://badge.fury.io/py/flask-google-cloud-logger)\n[![Maintainability](https://api.codeclimate.com/v1/badges/937c9f897f2cf89b9918/maintainability)](https://codeclimate.com/github/rai200890/flask_google_cloud_logger/maintainability)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/937c9f897f2cf89b9918/test_coverage)](https://codeclimate.com/github/rai200890/flask_google_cloud_logger/test_coverage)\n\nFlask extension to format logs according to Google Cloud v2 Specification\n\nPython 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\n\nInspired by Elixir's [logger_json](https://github.com/Nebo15/logger_json) \n\n## Instalation\n\n### Pipenv\n\n```\n    pipenv install flask_google_cloud_logger \n```\n\n### Pip\n\n```\n    pip install flask_google_cloud_logger \n```\n\n## Usage\n\n```python\nimport logging\nfrom logging import config\n\nfrom flask import Flask, request, g\nfrom flask_google_cloud_logger import FlaskGoogleCloudLogger\n\nLOG_CONFIG = {\n    \"version\": 1,\n    \"formatters\": {\n        \"json\": {\n            \"()\": \"flask_google_cloud_logger.FlaskGoogleCloudFormatter\",\n            \"application_info\": {\n                \"type\": \"python-application\",\n                \"application_name\": \"Example Application\"\n            },\n            \"format\": \"[%(asctime)s] %(levelname)s in %(module)s: %(message)s\"\n        }\n    },\n    \"handlers\": {\n        \"json\": {\n            \"class\": \"logging.StreamHandler\",\n            \"formatter\": \"json\"\n        }\n    },\n    \"loggers\": {\n        \"root\": {\n            \"level\": \"INFO\",\n            \"handlers\": [\"json\"]\n        },\n        \"werkzeug\": {\n            \"level\": \"WARN\",  # Disable werkzeug hardcoded logger\n            \"handlers\": [\"json\"]\n        }\n    }\n}\n\nconfig.dictConfig(LOG_CONFIG)  # load log config from dict\nlogger = logging.getLogger(\"root\")  # get root logger instance\napp = Flask(\"test_app\")\nFlaskGoogleCloudLogger(app)\n\n\n@app.route(\"/\")\ndef hello_world():\n    return \"Hello, World!\"\n\n\n@app.teardown_request #log request and response info after extension's callbacks\ndef log_request_time(_exception):\n    logger.info(\n        f\"{request.method} {request.path} - Sent {g.response.status_code}\" +\n        \" in {g.request_time:.5f}ms\")\n\n```\n\nExample output:\n\n```json\n{\"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\"}}\n```\n\n## Credits\n\nThanks [@thulio](https://github.com/thulio), [@robsonpeixoto](https://github.com/robsonpeixoto), [@ramondelemos](https://github.com/ramondelemos)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frai200890%2Fflask_google_cloud_logger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frai200890%2Fflask_google_cloud_logger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frai200890%2Fflask_google_cloud_logger/lists"}