Configure non-root logger?
spyoungtech opened this issue · 1 comments
spyoungtech commented
It seems that this library sets configuration on the root logger. Is there a way to set formatter on a non-root logger?
For example, we have loggers that do not propagate to the root logger that we'd like to have json logging for.
logger = logging.getLogger(__name__)
handler = logging.StreamHandler(sys.stderr)
# handler.setFormatter(...) # how to set json logging format here?
logger.addHandler(handler)
logger.propagate = False
...
Reason is we only want one particular log to have this format, while leaving other unchanged.
bobbui commented
you can explicitly add handler to that specific logger, something like that:
handler = logging.handlers.RotatingFileHandler(filename='log_req.log', maxBytes=5000000, backupCount=10)
handler.setFormatter(json_logging.JSONLogFormatter())
logger.addHandler(handler)