Package logging
[show private | 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-2009 Vinay Sajip. All Rights Reserved.

To use, simply 'import logging' and log away!
Submodules
  • config: Configuration functions for the logging package for Python.
  • handlers: Additional handlers for the logging package for Python.

Classes
_loggerClass Instances of the Logger class represent a single logging channel.
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.
Logger Instances of the Logger class represent a single logging channel.
LogRecord A LogRecord instance represents an event being logged.
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.

Function Summary
  addLevelName(level, levelName)
Associate 'levelName' with 'level'.
  basicConfig(**kwargs)
Do basic configuration for the logging system.
  critical(msg, *args, **kwargs)
Log a message with severity 'CRITICAL' on the root logger.
  debug(msg, *args, **kwargs)
Log a message with severity 'DEBUG' on the root logger.
  disable(level)
Disable all logging calls less severe than 'level'.
  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.
  fatal(msg, *args, **kwargs)
Log a message with severity 'CRITICAL' on the root logger.
  getLevelName(level)
Return the textual representation of logging level 'level'.
  getLogger(name)
Return a logger with the specified name, creating it if necessary.
  getLoggerClass()
Return the class to be used when instantiating a logger.
  info(msg, *args, **kwargs)
Log a message with severity 'INFO' on the root logger.
  log(level, msg, *args, **kwargs)
Log 'msg % args' with the integer severity 'level' on the root logger.
  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.
  shutdown()
Perform any cleanup actions in the logging system (e.g.
  warn(msg, *args, **kwargs)
Log a message with severity 'WARNING' on the root logger.
  warning(msg, *args, **kwargs)
Log a message with severity 'WARNING' on the root logger.

Variable Summary
str __author__ = 'Vinay Sajip <vinay_sajip@red-dove.com>'
str __date__ = '07 October 2005'
str __status__ = 'beta'
str __version__ = '0.4.9.7'
str BASIC_FORMAT = '%(levelname)s:%(name)s:%(message)s'
int CRITICAL = 50                                                                    
int DEBUG = 10                                                                    
int ERROR = 40                                                                    
int FATAL = 50                                                                    
int INFO = 20                                                                    
int NOTSET = 0                                                                     
int raiseExceptions = 1                                                                     
RootLogger root = <logging.RootLogger instance at 0x00A710A8>
int WARN = 30                                                                    
int WARNING = 30                                                                    

Function Details

addLevelName(level, levelName)

Associate 'levelName' with 'level'.

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

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.

critical(msg, *args, **kwargs)

Log a message with severity 'CRITICAL' on the root logger.

debug(msg, *args, **kwargs)

Log a message with severity 'DEBUG' on the root logger.

disable(level)

Disable all logging calls less severe than 'level'.

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.

fatal(msg, *args, **kwargs)

Log a message with severity 'CRITICAL' on the root logger.

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.

getLogger(name=None)

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

If no name is specified, return the root logger.

getLoggerClass()

Return the class to be used when instantiating a logger.

info(msg, *args, **kwargs)

Log a message with severity 'INFO' on the root logger.

log(level, msg, *args, **kwargs)

Log 'msg % args' with the integer severity 'level' on the root logger.

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. The class should define __init__() such that only a name argument is required, and the __init__() should call Logger.__init__()

shutdown()

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

Should be called at application exit.

warn(msg, *args, **kwargs)

Log a message with severity 'WARNING' on the root logger.

warning(msg, *args, **kwargs)

Log a message with severity 'WARNING' on the root logger.

Variable Details

__author__

Type:
str
Value:
'Vinay Sajip <vinay_sajip@red-dove.com>'                               

__date__

Type:
str
Value:
'07 October 2005'                                                      

__status__

Type:
str
Value:
'beta'                                                                 

__version__

Type:
str
Value:
'0.4.9.7'                                                              

BASIC_FORMAT

Type:
str
Value:
'%(levelname)s:%(name)s:%(message)s'                                   

CRITICAL

Type:
int
Value:
50                                                                    

DEBUG

Type:
int
Value:
10                                                                    

ERROR

Type:
int
Value:
40                                                                    

FATAL

Type:
int
Value:
50                                                                    

INFO

Type:
int
Value:
20                                                                    

NOTSET

Type:
int
Value:
0                                                                     

raiseExceptions

Type:
int
Value:
1                                                                     

root

Type:
RootLogger
Value:
<logging.RootLogger instance at 0x00A710A8>                            

WARN

Type:
int
Value:
30                                                                    

WARNING

Type:
int
Value:
30