Wilcox Development Solutions Blog

A Simple Write-to-a-file Turbogears 2 Logger

March 06, 2010

Turbogears uses Python’s logger module to perform logging operations. This has an advantage (it uses Python’s logger module) and an disadvantage (it uses Python’s logger module).

Be that as it may, here is the simplest configuration possible for you to log to a file (by default TG logs to your STDOUT device, which might not actually be what you want).

In (environment).ini (aka: development.ini)

Note: The format of logging section of this file follows the format laid down in the logging configuration file format section of the standard library documentation.


[handlers] keys = console, file # added file (line was: “keys = console”)

[loggerMYTGAPPNAME] # will be named whatever your TG app is named level = DEBUG handlers = file qualname = MYTGAPP_NAME

[handler_file] # added this section class = FileHandler args = (‘MYTGAPP_NAME/logs/foobar-debug.log’, ‘a+’) level = NOTSET formatter = generic


Accessing this in your code

`import logging log = logging.getLogger(“MYTGAPP_NAME”)

… code here …