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

Package logging

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.9

Date: 06 February 2006

Author: Vinay Sajip <vinay_sajip@red-dove.com>

Submodules [hide private]
  • logging.config: Configuration functions for the logging package for Python.
  • logging.handlers: Additional handlers for the logging package for Python.

Classes [hide private]
LogRecord
A LogRecord instance represents an event being logged.
Formatter
Formatter instances are used to convert a LogRecord to text.
BufferingFormatter
A formatter suitable for formatting a number of records.
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.
Handler
Handler instances dispatch logging events to specific destinations.
StreamHandler
A handler class which writes logging records, appropriately formatted, to a stream.
FileHandler
A handler class which writes formatted logging records to disk files.
PlaceHolder
PlaceHolder instances are used in the Manager logger hierarchy to take the place of nodes for which no loggers have been defined.
Manager
There is [under normal circumstances] just one Manager instance, which holds the hierarchy of loggers.
Logger
Instances of the Logger class represent a single logging channel.
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.
_loggerClass
Instances of the Logger class represent a single logging channel.
Functions [hide private]
 
getLevelName(level)
Return the textual representation of logging level 'level'.
 
addLevelName(level, levelName)
Associate 'levelName' with 'level'.
 
_acquireLock()
Acquire the module-level lock for serializing access to shared data.
 
_releaseLock()
Release the module-level lock acquired by calling _acquireLock().
 
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.
 
setLoggerClass(klass)
Set the class to be used when instantiating a logger.
 
getLoggerClass()
Return the class to be used when instantiating a logger.
 
basicConfig(**kwargs)
Do basic configuration for the logging system.
 
getLogger(name=None)
Return a logger with the specified name, creating it if necessary.
 
critical(msg, *args, **kwargs)
Log a message with severity 'CRITICAL' on the root logger.
 
fatal(msg, *args, **kwargs)
Log a message with severity 'CRITICAL' on the root logger.
 
error(msg, *args, **kwargs)
Log a message with severity 'ERROR' on the root logger.
 
exception(msg, *args)
Log a message with severity 'ERROR' on the root logger, with exception information.
 
warning(msg, *args, **kwargs)
Log a message with severity 'WARNING' on the root logger.
 
warn(msg, *args, **kwargs)
Log a message with severity 'WARNING' on the root logger.
 
info(msg, *args, **kwargs)
Log a message with severity 'INFO' on the root logger.
 
debug(msg, *args, **kwargs)
Log a message with severity 'DEBUG' on the root logger.
 
log(level, msg, *args, **kwargs)
Log 'msg % args' with the integer severity 'level' on the root logger.
 
disable(level)
Disable all logging calls less severe than 'level'.
 
shutdown(handlerList=[])
Perform any cleanup actions in the logging system (e.g.
 
exithook(status, old_exit=sys.exit)
Variables [hide private]
  __status__ = 'production'
  _srcfile = '/usr/lib/python2.5/logging/__init__.py'
  _startTime = 1213399525.65
  raiseExceptions = 1
  logThreads = 1
  logProcesses = 1
  CRITICAL = 50
  FATAL = 50
  ERROR = 40
  WARNING = 30
  WARN = 30
  INFO = 20
  DEBUG = 10
  NOTSET = 0
  _levelNames = {0: 'NOTSET', 10: 'DEBUG', 20: 'INFO', 30: 'WARN...
  _lock = None
  _defaultFormatter = Formatter()
  _handlers = {}
  _handlerList = []
  root = RootLogger(WARNING)
  BASIC_FORMAT = '%(levelname)s:%(name)s:%(message)s'

Imports: sys, os, types, time, string, cStringIO, traceback, codecs, threading, thread, currentframe, atexit, config, handlers


Function Details [hide private]

getLevelName(level)

 

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.

addLevelName(level, levelName)

 

Associate 'levelName' with 'level'.

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

_acquireLock()

 

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

This should be released with _releaseLock().

setLoggerClass(klass)

 

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__()

basicConfig(**kwargs)

 

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.

getLogger(name=None)

 

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

If no name is specified, return the root logger.

shutdown(handlerList=[])

 

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

Should be called at application exit.


Variables Details [hide private]

_levelNames

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