I have a pyramid application and I want the logs to got to stderr and stdout. stdout should be "INFO" level and below. stderr should be "WARN" and higher. How would I change my .ini file to do this?
Currently I am logging like this, is this considered the correct way?
log = logger.getLogger(__name__) log.info("update ...") log.error("MAYDAY MAYDAY... BOOM!!!")
Currently I am using the default logging, which is this.
[loggers] keys = root, app [handl开发者_开发知识库ers] keys = console [formatters] keys = generic [logger_root] level = WARN handlers = console [logger_app] level = WARN handlers = qualname = app [handler_console] class = StreamHandler args = (sys.stderr,) 85 level = NOTSET formatter = generic [formatter_generic] format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s
You can add multiple handlers to the root, comma-delimited. If you want to filter outside of the normal "only accept messages above this logging level" criterion (i.e. only debug messages) then you need to use something like a logging filter to accept/reject records based on their specific levels: http://docs.python.org/library/logging.html#filter-objects
Your current method of logging using log = logging.getLogger(__name__)
is perfectly valid and a convenient way to organize the logging hierarchy.
精彩评论