python - Python3 & PyCharm - Debug logging levels in run/debug -
i'm starting pycharm, there way show debug & info warnings?
import logging logger = logging.getlogger('tipper') logger.setlevel(logging.debug) logger.debug('debug message') logger.info('info message') logger.warn('warn message') logger.error('error message') logger.critical('critical message')
warn, error, critical show:
/home/username/someproject/.someprojectenv/bin/python3/home/username/someproject/go.py warn message error message critical message process finished exit code 0
however debug, info not show.
the problem has nothing pycharm, how logging configuration works. if try write code have shown in normal python interactive session same output:
>>> import logging >>> logger = logging.getlogger('tipper') >>> logger.setlevel(logging.debug) >>> logger.debug('debug message') >>> logger.info('info message') >>> logger.warn('warn message') warn message >>> logger.error('error message') error message >>> logger.critical('critical message') critical message
the problem setting logger
's level isn't enough! must add handler logger otherwise logger forward message chain. messages end @ root
logger, has, default, level of logging.warn
, discards debug
level messages.
however if add handler logger
works fine:
>>> logger.addhandler(logging.streamhandler()) >>> logger.debug('test') test
you can set more 1 handler each logger , each handler can have different logging level.
see this question bit of further information logger's , handler's levels. i'd suggest read documentation logging
module , various guides (e.g. logging
how-to, because has advanced configuration.
also python3.2 there's dictconfig
function allow specify configuration logging hierarchy dictionary, without having manually create every handler , logger hand.
Comments
Post a Comment