Changes between Version 1 and Version 2 of LoggingBestPractice


Ignore:
Timestamp:
10/08/06 17:21:20 (13 years ago)
Author:
spascoe
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • LoggingBestPractice

    v1 v2  
    11= Logging Best Practice = 
    22 
    3 A simple logging class already exists at [source:/TI12-security/trunk/python/NDG/Log.py], however far greater functionality and flexibility can be achieved by useing the python [http://docs.python.org/lib/module-logging.html logging] package.  All developers should familiarise themselves with this package document: in particular read the introduction because understanding the class-level pages is difficult without it. 
     3A simple logging class already exists at [source:/TI12-security/trunk/python/NDG/Log.py], however far greater functionality and flexibility can be achieved by useing the python [http://docs.python.org/lib/module-logging.html logging] package.  All developers should familiarise themselves with this package document: in particular read the introduction because understanding the class-level pages is difficult without it.  The discussion below assumes familiarity with the basics. 
    44 
    5 ...UNDER CONSTRUCTION... 
     5The key advantages of using the logging package is that when plugging packages together (such as dx and security) messages can be sent to different loggers in a logger heirarchy allowing decisions on how different messages are logged to be made by the application (script, webservice, etc) rather than the low-level module generating the message. 
     6 
     7This could include sending log messages to a remote logging service.  The logging package provides several remote logging handlers: SMTPHandler, SysLogHandler and HTTPHandler.  Alternatively we could implement our own logging handler to interact with a custom logging service. 
     8 
     9== Guidelines and requirements == 
    610 
    711All modules that wish to use the logging infrastructure should include the following lines: 
     
    1317This ensures that the logger heirarchy will always reflect the package heirarchy.  We would expect to end up with loggers such as "ndg.discovery.server" and "ndg.csml.parser". 
    1418 
    15 Subsequent logging should be done by calling methods on the logger object, rather than the functions provided in the logging package.  The latter will send messages to the root logger, thus bypassing any package-level filtering. 
     19Subsequent logging should be done by calling methods on the logger object, rather than the functions provided in the logging package (e.g. logging.debug()).  The latter will send messages to the root logger, thus bypassing any package-level filtering. 
    1620 
    17 All scripts that import modules that user logging must ensure that at least one handler is installed into the logging heirarchy.  The minimum code to do this is 
     21Any script that imports a module using logging must ensure that at least one handler is installed into the logging heirarchy.  The minimum code to do this is 
    1822{{{ 
    1923#!python