Package logging
[hide private]
[frames] | no frames]

Package logging

source code

Logging package for Python. Based on PEP 282 and comments thereto in comp.lang.python, and influenced by Apache's log4j system.

Should work under Python versions >= 1.5.2, except that source line information is not available unless 'sys._getframe()' is.

Copyright (C) 2001-2004 Vinay Sajip. All Rights Reserved.

To use, simply 'import logging' and log away!


Version: 0.4.9.7

Date: 07 October 2005

Author: Vinay Sajip <[email protected]>

Classes [hide private]
  BufferingFormatter
A formatter suitable for formatting a number of records.
  FileHandler
A handler class which writes formatted logging records to disk files.
  Filter
Filter instances are used to perform arbitrary filtering of LogRecords.
  Filterer
A base class for loggers and handlers which allows them to share common code.
  Formatter
Formatter instances are used to convert a LogRecord to text.
  Handler
Handler instances dispatch logging events to specific destinations.
  LogRecord
A LogRecord instance represents an event being logged.
  Logger
Instances of the Logger class represent a single logging channel.
  Manager
There is [under normal circumstances] just one Manager instance, which holds the hierarchy of loggers.
  PlaceHolder
PlaceHolder instances are used in the Manager logger hierarchy to take the place of nodes for which no loggers have been defined.
  RootLogger
A root logger is not that different to any other logger, except that it must have a logging level and there is only one instance of it in the hierarchy.
  StreamHandler
A handler class which writes logging records, appropriately formatted, to a stream.
  _loggerClass
Instances of the Logger class represent a single logging channel.
Functions [hide private]
 
_acquireLock()
Acquire the module-level lock for serializing access to shared data.
source code
 
_releaseLock()
Release the module-level lock acquired by calling _acquireLock().
source code
 
addLevelName(level, levelName)
Associate 'levelName' with 'level'.
source code
 
basicConfig(**kwargs)
Do basic configuration for the logging system.
source code
 
critical(msg, *args, **kwargs)
Log a message with severity 'CRITICAL' on the root logger.
source code
 
debug(msg, *args, **kwargs)
Log a message with severity 'DEBUG' on the root logger.
source code
 
disable(level)
Disable all logging calls less severe than 'level'.
source code
 
error(msg, *args, **kwargs)
Log a message with severity 'ERROR' on the root logger.
source code
 
exception(msg, *args)
Log a message with severity 'ERROR' on the root logger, with exception information.
source code
 
fatal(msg, *args, **kwargs)
Log a message with severity 'CRITICAL' on the root logger.
source code
 
getLevelName(level)
Return the textual representation of logging level 'level'.
source code
 
getLogger(name=None)
Return a logger with the specified name, creating it if necessary.
source code
 
getLoggerClass()
Return the class to be used when instantiating a logger.
source code
 
info(msg, *args, **kwargs)
Log a message with severity 'INFO' on the root logger.
source code
 
log(level, msg, *args, **kwargs)
Log 'msg % args' with the integer severity 'level' on the root logger.
source code
 
makeLogRecord(dict)
Make a LogRecord whose attributes are defined by the specified dictionary, This function is useful for converting a logging event received over a socket connection (which is sent as a dictionary) into a LogRecord instance.
source code
 
setLoggerClass(klass)
Set the class to be used when instantiating a logger.
source code
 
shutdown()
Perform any cleanup actions in the logging system (e.g.
source code
 
warn(msg, *args, **kwargs)
Log a message with severity 'WARNING' on the root logger.
source code
 
warning(msg, *args, **kwargs)
Log a message with severity 'WARNING' on the root logger.
source code
Variables [hide private]
  BASIC_FORMAT = '%(levelname)s:%(name)s:%(message)s'
  CRITICAL = 50
  DEBUG = 10
  ERROR = 40
  FATAL = 50
  INFO = 20
  NOTSET = 0
  WARN = 30
  WARNING = 30
  __status__ = 'beta'
  _defaultFormatter = <logging.Formatter instance at 0x81a80>
  _handlerList = [<ZConfig.components.logger.loghandler.StartupH...
  _handlers = {<logging.StreamHandler instance at 0x10715d0>: 1,...
  _levelNames = {0: 'NOTSET', 5: 'TRACE', 10: 'DEBUG', 15: 'BLAT...
  _lock = <_RLock(None, 0)>
  _srcfile = '/Library/Frameworks/Python.framework/Versions/2.4/...
  _startTime = 1193343983.97
  raiseExceptions = 1
  root = logging.getLogger()
Function Details [hide private]

_acquireLock()

source code 

Acquire the module-level lock for serializing access to shared data.

This should be released with _releaseLock().

addLevelName(level, levelName)

source code 

Associate 'levelName' with 'level'.

This is used when converting levels to text during message formatting.

basicConfig(**kwargs)

source code 

Do basic configuration for the logging system.

This function does nothing if the root logger already has handlers
configured. It is a convenience method intended for use by simple scripts
to do one-shot configuration of the logging package.

The default behaviour is to create a StreamHandler which writes to
sys.stderr, set a formatter using the BASIC_FORMAT format string, and
add the handler to the root logger.

A number of optional keyword arguments may be specified, which can alter
the default behaviour.

filename  Specifies that a FileHandler be created, using the specified
          filename, rather than a StreamHandler.
filemode  Specifies the mode to open the file, if filename is specified
          (if filemode is unspecified, it defaults to 'a').
format    Use the specified format string for the handler.
datefmt   Use the specified date/time format.
level     Set the root logger level to the specified level.
stream    Use the specified stream to initialize the StreamHandler. Note
          that this argument is incompatible with 'filename' - if both
          are present, 'stream' is ignored.

Note that you could specify a stream created using open(filename, mode)
rather than passing the filename and mode in. However, it should be
remembered that StreamHandler does not close its stream (since it may be
using sys.stdout or sys.stderr), whereas FileHandler closes its stream
when the handler is closed.

getLevelName(level)

source code 

Return the textual representation of logging level 'level'.

If the level is one of the predefined levels (CRITICAL, ERROR, WARNING, INFO, DEBUG) then you get the corresponding string. If you have associated levels with names using addLevelName then the name you have associated with 'level' is returned.

If a numeric value corresponding to one of the defined levels is passed in, the corresponding string representation is returned.

Otherwise, the string "Level %s" % level is returned.

getLogger(name=None)

source code 

Return a logger with the specified name, creating it if necessary.

If no name is specified, return the root logger.

setLoggerClass(klass)

source code 
Set the class to be used when instantiating a logger. The class should define __init__() such that only a name argument is required, and the __init__() should call Logger.__init__()

shutdown()

source code 

Perform any cleanup actions in the logging system (e.g. flushing buffers).

Should be called at application exit.

Variables Details [hide private]

_handlerList

Value:
[<ZConfig.components.logger.loghandler.StartupHandler instance at 0x10\
71648>,
 <logging.StreamHandler instance at 0x10715d0>]

_handlers

Value:
{<logging.StreamHandler instance at 0x10715d0>: 1,
 <ZConfig.components.logger.loghandler.StartupHandler instance at 0x10\
71648>: 1}

_levelNames

Value:
{0: 'NOTSET',
 5: 'TRACE',
 10: 'DEBUG',
 15: 'BLATHER',
 20: 'INFO',
 30: 'WARNING',
 40: 'ERROR',
 50: 'CRITICAL',
...

_srcfile

Value:
'/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/loggi\
ng/__init__.py'