Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pyramid logging

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

[handlers]
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
like image 553
Conceited Code Avatar asked Jun 02 '11 19:06

Conceited Code


1 Answers

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.

like image 104
Michael Merickel Avatar answered Oct 21 '22 16:10

Michael Merickel