skyork
skyork

Reputation: 7381

Web2py logging by importing Python logger

I followed the details in the Web2py manual, and setup my logger this way:

I first re-named the config file 'logging.example.conf' to 'logging.conf' in the Web2py root directory, and add 'myapp' to the list of loggers

[loggers]
keys=root,rocket,markdown,web2py,rewrite,app,welcome,myapp

and add a separate 'logger_myapp' section too

[logger_myapp]
level=DEBUG
qualname=web2py.app.myapp
handlers=consoleHandler
propagate=0 

and then in some model file of myapp, I wrote:

import logging
logger = logging.getLogger("web2py.app.myapp')
logger.setLevel(logging.DEBUG)

and somewhere down in the same model file, I tried to test the logging by doing:

logger.debug("Check: %s" % details)

where details is just a variable holding a string

However, when I ran Web2py from the command line, i.e. python web2py.py, and when the model file is executed, I see nothing coming out the console.

What did I miss here?

Upvotes: 1

Views: 1416

Answers (1)

JLundell
JLundell

Reputation: 1610

You probably just need to set the level of handler_consoleHandler to DEBUG. Both the logger and the handler have levels associated with them, and either one can filter your output.

[handler_consoleHandler]
class=StreamHandler
level=DEBUG <<<<<<<<<<<<<<<<
formatter=simpleFormatter
args=(sys.stdout,)

Upvotes: 3

Related Questions