python_google_cloud_logger
Python log formatter for Google Cloud according to v2 specification using python-json-logger formatter
Inspired by Elixir's logger_json
Instalation
Pipenv
pipenv install google_cloud_logger
Pip
pip install google_cloud_logger
Usage
LOG_CONFIG = {
"version": 1,
"formatters": {
"json": {
"()": "google_cloud_logger.GoogleCloudFormatter",
"application_info": {
"type": "python-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"]
}
}
}
import logging
from logging import config
config.dictConfig(LOG_CONFIG) # load log config from dict
logger = logging.getLogger("root") # get root logger instance
logger.info("farofa", extra={"extra": "extra"}) # log message with extra arguments
Example output:
{"timestamp": "2018-11-03T22:05:03.818000Z", "severity": "INFO", "message": "farofa", "labels": {"type": "python-application", "name": "Example Application"}, "metadata": {"userLabels": {"extra": "extra"}}, "sourceLocation": {"file": "<ipython-input-9-8e9384d78e2a>", "line": 1, "function": "<module>"}}
Credits
Thanks @thulio, @robsonpeixoto, @ramondelemos
Metadata
Release files for google-cloud-logger 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| google_cloud_logger-0.1.1.tar.gz | 4.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| google_cloud_logger-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.1 kB
Release files / google_cloud_logger-0.1.1.tar.gz
| Download URL | google_cloud_logger-0.1.1.tar.gz |
|---|---|
| Size | 4.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d1f92e6f562d20c11a1f7099d9ebbd71622854afaeeffa7a0e5457ca2abb25d5
|
|
BLAKE2b-256 checksum How to use checksums |
fa9c494a2c80030fb16c48d9401292c8903dcc5f60c3848de54e5744e528b23c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6
|
Release files / google_cloud_logger-0.1.1-py3-none-any.whl
| Download URL | google_cloud_logger-0.1.1-py3-none-any.whl |
|---|---|
| Size | 6.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a8b4179905fc96a9d01ae313b949de973219950082c5b35d7bc0ce81e480a281
|
|
BLAKE2b-256 checksum How to use checksums |
400f4cc77fc88a5b703c9f37c1c64f1212064313bc242eed326ed4f8c3ec1f16
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6
|