Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Changes between Version 7 and Version 8 of logging


Ignore:
Timestamp:
06/09/06 21:59:01 (11 years ago)
Author:
anonymous
Comment:

spellcheck

Legend:

Unmodified
Added
Removed
Modified
  • logging

    v7 v8  
    1 = Undestanding the Logger = 
     1= Understanding the Logger = 
    22 
    33As the [http://www.blueskyonmars.com/2006/04/29/turbogears-09a5-released/ original post] said TurboGears uses the Python standard library logger module, which you can read about in detail in the [http://docs.python.org/lib/module-logging.html official Python docs]. 
     
    2020}}} 
    2121 
    22 That is the prefered way to create a logger. The param string is the name of your new logger. Although this could be anything you want, it's good practice to follow a convention and keep your logs organized from the get go. Here we name the logger after the package/module since this is a unique name. 
     22That is the preferred way to create a logger. The param string is the name of your new logger. Although this could be anything you want, it's good practice to follow a convention and keep your logs organized from the get go. Here we name the logger after the package/module since this is a unique name. 
    2323 
    2424Next, send some info to our new logger object: 
     
    3434Because then you'd be shorting yourself on the power and flexibility of the python logging module.  We want to be able to send our logs to [http://docs.python.org/lib/multiple-destinations.html Multiple Destinations], as defined by you, so you can later find out if the error is on your side or on the framework just by looking at the logs. You can also send different logs to different places, all without sprinkling your app code with needless boilerplate code, thanks to the config files. 
    3535 
    36 In general is a better practice to do it the first way and take full advantage of the python logging module. If not, it's only one extra line of code, anwyways. 
     36In general is a better practice to do it the first way and take full advantage of the python logging module. If not, it's only one extra line of code, anyways. 
    3737 
    3838= TurboGears .cfg files = 
    3939If you are used to the "normal" way of creating loggers, either by [http://docs.python.org/lib/logging-config-api.html loggingConfig] or [http://docs.python.org/lib/logging-config-fileformat.html config files] you may get confused by this format. 
    4040 
    41 So lets start with the format. This config file is read by ConfigObj and you can check out the documentation for the  [http://www.voidspace.org.uk/python/configobj.html#the-config-file-format ConfigObj File Format] for more detail. For our purposes here the only diference from standard library [http://docs.python.org/lib/module-ConfigParser.html ConfigParser] is the nested tags, which will generate a dictionary of the tag name and fill it with whatevers in that nested section. If you want to explore the goodness of ConfigObj, take a look at the  [http://www.voidspace.org.uk/python/configobj.html docs], especially the part about storing python types in a config file [http://www.voidspace.org.uk/python/configobj.html#unrepr-mode storing python types in a config file], which might clear up what's going on in the default [wiki:logging#inlog.cfg log.cfg]. 
     41So let's start with the format. This config file is read by ConfigObj and you can check out the documentation for the  [http://www.voidspace.org.uk/python/configobj.html#the-config-file-format ConfigObj File Format] for more detail. For our purposes here the only difference from standard library [http://docs.python.org/lib/module-ConfigParser.html ConfigParser] is the nested tags, which will generate a dictionary of the tag name and fill it with whatever's in that nested section. If you want to explore the goodness of ConfigObj, take a look at the  [http://www.voidspace.org.uk/python/configobj.html docs], especially the part about storing python types in a config file [http://www.voidspace.org.uk/python/configobj.html#unrepr-mode storing python types in a config file], which might clear up what's going on in the default [wiki:logging#inlog.cfg log.cfg]. 
    4242 
    4343== What is this *()  == 
    44 Think of it as `%()` since we can't put it into a config file, as ConfigObj interprets it as something else. Just a [source:/tags/0.9a5/turbogears/config.py#L117 slight] [source:/browser/tags/0.9a5/turbogears/config.py#L23 hack], nothing to see here, move along... 
     44Think of it as `%()` since we can't put it into a config file, as ConfigObj interprets it as something else. Just a [source:/tags/0.9a5/turbogears/config.py#L117 slight] [source:/tags/0.9a5/turbogears/config.py#L23 hack], nothing to see here, move along... 
    4545 
    4646== Logging Config Format == 
     
    8585 
    8686== Loggers == 
    87 This is a another way to create [http://docs.python.org/lib/node341.html Logger Objects].  You can either define them here or do the calls in your code, it depends on your situation/taste. Code accomplishing the same thing follow the descriptions of the parameters. 
     87This is another way to create [http://docs.python.org/lib/node341.html Logger Objects].  You can either define them here or do the calls in your code, it depends on your situation/taste. Code accomplishing the same thing follow the descriptions of the parameters. 
    8888 
    8989`qualname` 
     
    153153}}} 
    154154 
    155 Can you follow it yet? We define 2 formatters named "message_only" and "full_content", then we pick 3 handlers which all stream to stdout but with different levels and using the two formaters we defined in the same file. 
     155Can you follow it yet? We define 2 formatters named "message_only" and "full_content", then we pick 3 handlers which all stream to stdout but with different levels and using the two formatters we defined in the same file. 
    156156 
    157157=== dev.cfg === 
     
    184184= Conclusion = 
    185185 
    186 Now that you undestand how it works it's time to turn it around and do lots of stuff with it. Check out LoggingConfigurationExamples for more. 
     186Now that you understand how it works it's time to turn it around and do lots of stuff with it. Check out LoggingConfigurationExamples for more. 
    187187 
    188188TODO add patch to add custom levels