A JSON logger for map colonies project
Project description
json-logger
Installation
Installation with dependencies
pip3 install python-json-logger MapColoniesJSONLogger
Usage Example
import os
from jsonlogger.logger import JSONLogger
APP_NAME = 'my-service'
# there should be a formatter that uses these fields in configuration yaml (e.g. format: '%(timestamp)s %(service)s')
additional_constant_fields = {'service': APP_NAME}
# NOTICE: there should be a matching logger name in configuration yaml (e.g. main-info)
log = JSONLogger('main-info',
config={'handlers': {'file': {'filename': 'Meow.log'}}}, # Optional, override values
additional_fields=additional_constant_fields)
log.critical('system crashed')
log.error('incorrect input')
log.warn('not ready')
log.info('some info', extra={'action_id': 3}) # extra fields
log.debug('some info', extra={'action_id': 4}) # will not be logged because logger level set to INFO ('main-info')
Example Configuration YAML used by the package
{
'version': 1,
'formatters': {
'brief': {
'format': '%(message)s'
},
'json': {
'format': '%(timestamp)s %(service)s %(loglevel)s %(message)s',
'class': 'jsonlogger.logger.CustomJsonFormatter'
}
},
'handlers': {
'console': {
'class': 'logging.StreamHandler',
'formatter': 'json',
'stream': 'ext://sys.stdout'
},
'file': {
'class': 'logging.handlers.RotatingFileHandler',
'formatter': 'json',
'filename': '/var/log/osm-seed/logfile.log',
'maxBytes': 5242880,
'backupCount': 10
}
},
'loggers': {
'main-debug': {
'handlers': [
'console',
'file'
],
'level': 'DEBUG'
},
'main-info': {
'handlers': [
'console',
'file'
],
'level': 'INFO'
},
'main-warning': {
'handlers': [
'console',
'file'
],
'level': 'WARNING'
},
'main-error': {
'handlers': [
'console',
'file'
],
'level': 'ERROR'
},
'main-critical': {
'handlers': [
'console',
'file'
],
'level': 'CRITICAL'
}
}
}
Project details
Release history Release notifications | RSS feed
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 MapColoniesJSONLogger-0.0.12.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | cfc05b2e91c5ade57866c57dfdb7c78e85cc15ce81e1cbf80b34f14a9192ad7d |
|
MD5 | cb9c719c0c9e99075d12b5393cb3e1bf |
|
BLAKE2b-256 | 16918403b90ead342a972737022179c2e7772cdea77865fd81754e29a400981c |
Close
Hashes for MapColoniesJSONLogger-0.0.12-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 212ad5b85b06d6d606db5e1151e082da0d3912078008e9e1df8ccd422aa4fe61 |
|
MD5 | 40e78683d92ff6847f31a0846174ed19 |
|
BLAKE2b-256 | c234338c5b6145021995ecf77941f8a241b2470f1b12aa73daf8b580c42e7294 |