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_file=os.environ.get('LOG_CONFIG_PATH'), # optional, if not passed a default log.yaml is used
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: logfile.log # log files full path, if a path is used make sure the directory exists
maxBytes: 5242880 # 5 MB
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.9.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8739ceb306b61a5ea7f6d71318e7e985752e7dead0be4dc250e8c27be3a91cd2 |
|
MD5 | 1d93eb68b4695be2a17cc8a98b6f91e3 |
|
BLAKE2b-256 | 94d4fb10eda7aa068bf293c7e4ab98365713ee4d70c028ee3c54cfc25861649c |
Close
Hashes for MapColoniesJSONLogger-0.0.9-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 34eddde4d7a84f85b76273acd6d78e1ecb5e9f93efc8efac075af8a4bed97662 |
|
MD5 | 2ab45844bb4236633ad0b6d1795188dc |
|
BLAKE2b-256 | 8729ffbed55bff8782fdef44ecd7fd73b582266cddb5d380f79b672a302c9efa |