Title: Logging: 'client.setup_logging()' doesn't identify the underlying platform · Issue #7 · googleapis/python-logging · GitHub
Open Graph Title: Logging: 'client.setup_logging()' doesn't identify the underlying platform · Issue #7 · googleapis/python-logging
X Title: Logging: 'client.setup_logging()' doesn't identify the underlying platform · Issue #7 · googleapis/python-logging
Description: My objective is to format correctly the logs into my Python app for having a good ingestion and formatting on Stackdriver logging console with level well interpreted. The standard logging doesn't work for App Engine python 3.7 (work in P...
Open Graph Description: My objective is to format correctly the logs into my Python app for having a good ingestion and formatting on Stackdriver logging console with level well interpreted. The standard logging doesn't w...
X Description: My objective is to format correctly the logs into my Python app for having a good ingestion and formatting on Stackdriver logging console with level well interpreted. The standard logging doesn'...
Opengraph URL: https://github.com/googleapis/python-logging/issues/7
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Logging: 'client.setup_logging()' doesn't identify the underlying platform","articleBody":"My objective is to format correctly the logs into my Python app for having a good ingestion and formatting on Stackdriver logging console with level well interpreted.\r\n\r\nThe standard logging doesn't work for App Engine python 3.7 (work in Python 2) and on Cloud Run, because the logs aren't formatted in FluentD.\r\nHowever, with Cloud Function, it's the case.\r\n\r\nI found how to perform a workaround, (see example), but I think there is a bug in your library. Indeed, the function `client.setup_logging()` should set up my logger with the correct format according with the environment.\r\n\r\nIt's not the case, and that's why I have to implement the workaround. Sadly, this workaround don't take into account the environment and when I run locally the app, I have this log trace:\r\n\r\n```\r\n * Serving Flask app \"server\" (lazy loading)\r\n * Environment: production\r\n WARNING: This is a development server. Do not use it in a production deployment.\r\n Use a production WSGI server instead.\r\n * Debug mode: off\r\n{\"message\": \" * Running on http://0.0.0.0:8080/ (Press CTRL+C to quit)\", \"timestamp\": {\"seconds\": 1571789029, \"nanos\": 987048387}, \"thread\": 140201867048192, \"severity\": \"INFO\"}\r\n{\"message\": \"call info1\", \"timestamp\": {\"seconds\": 1571789035, \"nanos\": 285192966}, \"thread\": 140201732208384, \"severity\": \"INFO\"}\r\n{\"message\": \"call info2\", \"timestamp\": {\"seconds\": 1571789035, \"nanos\": 285630702}, \"thread\": 140201732208384, \"severity\": \"INFO\"}\r\n{\"message\": \"this is an error2\", \"timestamp\": {\"seconds\": 1571789035, \"nanos\": 285893201}, \"thread\": 140201732208384, \"severity\": \"ERROR\"}\r\n{\"message\": \"127.0.0.1 - - [23/Oct/2019 02:03:55] \\\"GET / HTTP/1.1\\\" 200 -\", \"timestamp\": {\"seconds\": 1571789035, \"nanos\": 286895513}, \"thread\": 140201732208384, \"severity\": \"INFO\"}\r\n```\r\nWhich is in FluentD format, but barely lisible.\r\n\r\nThe automatic configuration promised at [this page](https://googleapis.dev/python/logging/latest/usage.html#integration-with-python-logging-module) doesn't happen!\r\n\r\n#### Environment details\r\n\r\n1. Specify the API at the beginning of the title (for example, \"BigQuery: ...\")\r\n General, Core, and Other are also allowed as types\r\n\r\nLogging API for App Engine and Cloud Run\r\n\r\n2. OS type and version\r\nPython 3.7, linux( appengine, container, local environment)\r\n\r\n3. Python version and virtual environment information: `python --version`\r\n3.7. Version not detailed because occur on App Engine\r\n\r\n4. google-cloud-\u003cservice\u003e version: `pip show google-\u003cservice\u003e` or `pip freeze`\r\ngoogle-cloud-logging==1.14.0\r\n\r\n#### Steps to reproduce\r\n\r\n Deploy an app on Cloud Run or App Engine standard Python 3.7. Bellow an example with the workaround. Try to change the log handler with `client.setup_logging()` no special formater are set, and the log on Stackdriver aren't well ingested.\r\n\r\n#### Code example\r\n\r\nThis is a working example. I don't use client.setup_logging()\r\n\r\n```python\r\nimport os\r\nfrom flask import Flask, request\r\nimport logging\r\nfrom google.cloud.logging.handlers.container_engine import ContainerEngineHandler\r\n\r\n\r\n# This change nothing to the standard logger on App Engine and Cloud Run env\r\n# client = google.cloud.logging.Client()\r\n# client.setup_logging()\r\n\r\n# This is a working workaround on GCP but with not lisible log in local env\r\nhandler = ContainerEngineHandler()\r\ncloud_logger = logging.getLogger()\r\ncloud_logger.setLevel(logging.DEBUG)\r\ncloud_logger.addHandler(handler)\r\n\r\napp = Flask(__name__)\r\n@app.route('/', methods=['GET'])\r\n\r\ndef call_oracle_connection():\r\n logger = logging.getLogger(\"cloudLogger\")\r\n logger.info('call info1')\r\n logger = logging.getLogger()\r\n logger.info('call info2')\r\n logging.error('this is an error2')\r\n return oracle_connection(request)\r\n\r\nif __name__ == \"__main__\":\r\n app.run(host='0.0.0.0',port=int(os.environ.get('PORT',8080)))\r\n```\r\n\r\nThanks!\r\n","author":{"url":"https://github.com/guillaumeblaquiere","@type":"Person","name":"guillaumeblaquiere"},"datePublished":"2019-10-25T13:12:51.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":9},"url":"https://github.com/7/python-logging/issues/7"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:b7825bf1-11f7-cc63-86dd-d8b5f36ef5aa |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 91DE:51AE:1A583C:23A9A5:6A52E278 |
| html-safe-nonce | a08d949d32677f4ea7e20ac2ecbc2b90d34061a92204b9b65373e457cdb2e701 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MURFOjUxQUU6MUE1ODNDOjIzQTlBNTo2QTUyRTI3OCIsInZpc2l0b3JfaWQiOiI5MTA1MDA2MTAyOTIwMjI1NDAwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 34ae33d748a4226502aa047672b718a5f61681f34f0388a5414e6c10d6618824 |
| hovercard-subject-tag | issue:560388315 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/googleapis/python-logging/7/issue_layout |
| twitter:image | https://opengraph.githubassets.com/62d27570c2a0e36b471a56f62ac626a89020aca26ee00356dcd582e2cb2e00a5/googleapis/python-logging/issues/7 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/62d27570c2a0e36b471a56f62ac626a89020aca26ee00356dcd582e2cb2e00a5/googleapis/python-logging/issues/7 |
| og:image:alt | My objective is to format correctly the logs into my Python app for having a good ingestion and formatting on Stackdriver logging console with level well interpreted. The standard logging doesn't w... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | guillaumeblaquiere |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| go-import | github.com/googleapis/python-logging git https://github.com/googleapis/python-logging.git |
| octolytics-dimension-user_id | 16785467 |
| octolytics-dimension-user_login | googleapis |
| octolytics-dimension-repository_id | 226992562 |
| octolytics-dimension-repository_nwo | googleapis/python-logging |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 226992562 |
| octolytics-dimension-repository_network_root_nwo | googleapis/python-logging |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width