A JSON logger for map colonies project
Project description
json-logger
Installation
pip3 install mapcoloniesjsonlogger
Usage Example
from jsonlogger.logger import JSONLogger
APP_NAME = 'my-service'
# NOTICE: there should be a formatter that uses these fields in configuration dict (e.g. format: '%(timestamp)s %(service)s')
additional_constant_fields = {'service': APP_NAME}
# NOTICE: there should be a matching logger name in configuration dict (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')
Configuration Example
The configuration dict bellow is used by the package. For more information on logging configuration see logging.config docs
{
'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/map-colonies/service.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.16.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a909c810d80ddcd4d0838f08cc067f3aa74dbbedf9fed3596e23dde9b0c214a8 |
|
MD5 | ff28d09a8394e91c170cfad0092da55d |
|
BLAKE2b-256 | 504f00d9677da8cf7b5fbd1b5ac971f32530673c1f03dc2ca3fd84454c7f61e8 |
Close
Hashes for MapColoniesJSONLogger-0.0.16-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74f7273e0acbf0662e8d828c0310f4b0b804af809a9284e97da51fb5299ee906 |
|
MD5 | 6d8c836ca0c8911ed20ba5ab68f03746 |
|
BLAKE2b-256 | 6afd826db3f36669e4ad90e0c9cab37ccd7481e43df9d34ee99bd65641b42b61 |