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 5 and Version 6 of logging


Ignore:
Timestamp:
06/06/06 20:15:08 (13 years ago)
Author:
Kaan
Comment:

Partially edited document, the rest should be done by tomorrow

Legend:

Unmodified
Added
Removed
Modified
  • logging

    v5 v6  
    11= Undestanding the Logger = 
    22 
    3 As the original post<link to post> said this is a normal python logger so we go to http://docs.python.org/lib/module-logging.html to learn how to use it.  
    4 the're 2 places where logging is stored both mark by the tag [logging] your dev/prod.cfg and the config/log.cfg the idea is that log.cfg will have things that don't change based on the location. 
     3As 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]. 
    54 
    6 Please note <your package> is use across this doc, on your local copy it should say the name of your project's package 
     5The default Turbogears logging is defined in two places: 
     6 1. ''dev.cfg'' and ''prod.cfg'' - From your quickstart directory, contains configuration specific to your environment 
     7 1. ''<your package>/config/log.cfg'' - Contains configuration for your logging that won't change based on your environment 
     8 
     9Logging specific configuration is marked by the tag [logging] in both of these files. 
     10 
     11Please note the ''<your package>'' used throughout this doc. Remember to substitute your app's packagename when you try these things out for yourself. 
    712 
    813= Using the Logger = 
    9 Basically what you need is a quick read of http://docs.python.org/lib/module-logging.html, the first page is sufficient for now, 
     14To get the most out of this section, check out the [http://docs.python.org/lib/module-logging.html first page] of the logging module docs. 
    1015 
    11 after that two lines in your controllers.py is all you need to get going 
     16Two lines in your controllers.py are all you need to get going. First, create a logger: 
    1217 
    1318{{{ 
     
    1520}}} 
    1621 
    17 That is the prefered way to create a logger the param string is the name which could be anything, although it's good practice to follow a convention, here TG by default suggest to name the logger after the package/module since this is a unique name. 
     22That 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. 
    1823 
    19 the other line you should care about is 
     24Next, send some info to our new logger object: 
    2025 
    2126{{{ 
     
    2328}}} 
    2429 
    25 Which as you read in http://docs.python.org/lib/module-logging.html u did right? is a log with level 10 you also should know that  
     30Which, as you read in the official docs, is a log with level 10, the debug level of severity. You can probably just ignore the level numbers, unless you want to create log levels of your own. 
    2631 
    2732== Why not just use logging.debug(msg)? == 
    2833 
    29 because we want to be able to do this [http://docs.python.org/lib/multiple-destinations.html Multiple Destinations] 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 diferent logs to diferent places, in general is a better practice to do it this way, and you will take full advantage of the python logging module. 
     34Because 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. 
     35 
     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, anwyways. 
    3037 
    3138= TurboGears .cfg files =