A JSON logger for map colonies project
Project description
json-logger
Dependencies
install python-json-logger
pip3 install python-json-logger
Usage Example
NOTICE: the example assumes that logger.py is in the same directory as your calling module, else a different import method should be used
import os
from json_logger.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-debug)
log = JSONLogger('main-info',
config_file=os.environ.get('LOG_CONFIG_PATH'),
additional_fields=additional_constant_fields).get_logger()
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: 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
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.8.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d789ac98a4000ce291bb13b59f2fb87ae44ba9eaedbbad7db73b0c127063e61 |
|
MD5 | afe9065439fb779558001a423db421ef |
|
BLAKE2b-256 | 6b1a81789d73588e7fad53c83dd3840c29c1a19fbbd724d24de87b4049c55877 |
Close
Hashes for MapColoniesJSONLogger-0.0.8-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ef515ca14657f2f306412147cf740c16ae2641d5f6c17dc37a4e2d9bad14511d |
|
MD5 | d04ce269dd8a9be9626fd9556130f976 |
|
BLAKE2b-256 | 7129dc55e41f76e5309fb03c86ddeb6e8550a4c7fc9dd9972cdefa305b4acd5c |