Closed koki-nakamura22 closed 2 years ago
An example code 2. -> Output log to console.
def test_log2():
from logging import INFO, getLogger, StreamHandler, Formatter, basicConfig
log_level = INFO
stream_handler = StreamHandler()
stream_handler.setLevel(log_level)
stream_handler.setFormatter(
Formatter("[%(asctime)s]:%(levelname)s:%(message)s:%(additionaldata)s"))
basicConfig(level=log_level, handlers=[stream_handler])
logger = getLogger('test')
logger.setLevel(log_level)
logger.debug('debug', extra={'additionaldata': 'debug'})
logger.debug('debug2', extra={'additionaldata': 'debug2'})
logger.info('info', extra={'additionaldata': {"name": "Koki"}})
An example code.