Google Cloud Logger Formatter
Project description
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
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file google_cloud_logger-0.2.1.tar.gz
.
File metadata
- Download URL: google_cloud_logger-0.2.1.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.0 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2c232c22c8e78b16dcef2d06000f4a0229ef6837f2a4bc0d4bd6efbcc6ada15 |
|
MD5 | aa7cb2189c463559635a7458756e27e3 |
|
BLAKE2b-256 | 168a7596ffed2de144c6d08b30d698a24db4f7c4378e0871b8c6805f9d1bea0c |
File details
Details for the file google_cloud_logger-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: google_cloud_logger-0.2.1-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.0 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c3a998ec5f4285340c919691c71e9df26b518e81432a1e88cfc37ca3f0e40133 |
|
MD5 | 2d75cad444e9c43bf8da6ad0ca0de2c9 |
|
BLAKE2b-256 | 8ad3fe994f9f5de1c5f3d0073efdef5f442bee7388c7a565ee93eb6a2eb51e69 |