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
Close
Hashes for google_cloud_logger-0.2.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2c232c22c8e78b16dcef2d06000f4a0229ef6837f2a4bc0d4bd6efbcc6ada15 |
|
MD5 | aa7cb2189c463559635a7458756e27e3 |
|
BLAKE2b-256 | 168a7596ffed2de144c6d08b30d698a24db4f7c4378e0871b8c6805f9d1bea0c |
Close
Hashes for google_cloud_logger-0.2.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c3a998ec5f4285340c919691c71e9df26b518e81432a1e88cfc37ca3f0e40133 |
|
MD5 | 2d75cad444e9c43bf8da6ad0ca0de2c9 |
|
BLAKE2b-256 | 8ad3fe994f9f5de1c5f3d0073efdef5f442bee7388c7a565ee93eb6a2eb51e69 |