#!/usr/bin/python3 -u
import logging
from logging import config
from time import sleep
LOGGING_CONFIG = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'standard': {
'format': '[%(asctime)s] %(levelname)s | %(name)s: %(message)s',
'datefmt': '%Y-%m-%d %H:%M:%S',
},
},
'handlers': {
'init': {
'level': 'INFO',
'formatter': 'standard',
'class': 'logging.StreamHandler',
'stream': 'ext://sys.stdout',
},
'getmail': {
'level': 'INFO',
'formatter': 'standard',
'class': 'logging.StreamHandler',
'stream': 'ext://sys.stdout',
},
'parse': {
'level': 'INFO',
'formatter': 'standard',
'class': 'logging.StreamHandler',
'stream': 'ext://sys.stdout',
},
},
'loggers': {
'': {
'level': 'NOTSET',
'handlers': ['init', 'getmail', 'parse'],
'propagate': 1,
}
},
}
def agent_getmail():
sleep(1)
logger = logging.getLogger('getmail')
logger.debug('getmail - debug')
logger.info('getmail - info')
logger.error('getmail - error')
return True
def agent_parse():
sleep(1)
logger = logging.getLogger('parse')
logger.debug('parse - debug')
logger.info('parse - info')
logger.error('parse - error')
return True
def main():
logging.config.dictConfig(LOGGING_CONFIG)
logger = logging.getLogger('init')
logger.debug('init - debug')
logger.info('init - info')
logger.error('init - error')
agent_getmail()
agent_parse()
if __name__ == "__main__":
main()
[2020-12-22 12:05:33] INFO | init: init - info
[2020-12-22 12:05:33] INFO | init: init - info
[2020-12-22 12:05:33] INFO | init: init - info
[2020-12-22 12:05:33] ERROR | init: init - error
[2020-12-22 12:05:33] ERROR | init: init - error
[2020-12-22 12:05:33] ERROR | init: init - error
[2020-12-22 12:05:34] INFO | getmail: getmail - info
[2020-12-22 12:05:34] INFO | getmail: getmail - info
[2020-12-22 12:05:34] INFO | getmail: getmail - info
[2020-12-22 12:05:34] ERROR | getmail: getmail - error
[2020-12-22 12:05:34] ERROR | getmail: getmail - error
[2020-12-22 12:05:34] ERROR | getmail: getmail - error
[2020-12-22 12:05:35] INFO | parse: parse - info
[2020-12-22 12:05:35] INFO | parse: parse - info
[2020-12-22 12:05:35] INFO | parse: parse - info
[2020-12-22 12:05:35] ERROR | parse: parse - error
[2020-12-22 12:05:35] ERROR | parse: parse - error
[2020-12-22 12:05:35] ERROR | parse: parse - error
LOGGING_CONFIG = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'standard': {
'format': '[%(asctime)s] %(levelname)s | %(name)s: %(message)s',
'datefmt': '%Y-%m-%d %H:%M:%S',
},
},
'handlers': {
'std': {
# 'level': 'INFO',
'formatter': 'standard',
'class': 'logging.StreamHandler',
'stream': 'ext://sys.stdout',
},
},
'loggers': {
'init': {
'level': 'DEBUG',
'handlers': ['std'],
'propagate': 1,
},
'parse': {
'level': 'DEBUG',
'handlers': ['std'],
'propagate': 1,
},
'getmail': {
'level': 'DEBUG',
'handlers': ['std'],
'propagate': 1,
},
},
}