Package flumotion :: Package common :: Module log
[show private | hide private]
[frames | no frames]

Module flumotion.common.log

Flumotion logging

Just like in GStreamer, five levels of log information are defined. These are, in order of decreasing verbosity: log, debug, info, warning, error.

API Stability: stabilizing

Maintainer: Thomas Vander Stichele
Classes
FluLogObserver Twisted log observer that integrates with Flumotion's logging.
Loggable Base class for objects that want to be able to log messages with different level of severity.

Function Summary
  addLogHandler(func, limited)
Add a custom log handler.
  debug(cat, format, *args)
  debugObject(object, cat, format, *args)
Log a debug message in the given category.
  doLog(level, object, category, format, args, where, file, line)
Return dict of calculated variables, if they needed calculating.
  ellipsize(o)
Ellipsize the representation of the given object.
  error(cat, format, *args)
  errorObject(object, cat, format, *args)
Log a fatal error message in the given category.
  getCategoryLevel(category)
  getExceptionMessage(exception, frame, filename)
Return a short message based on an exception, useful for debugging.
  getFailureMessage(failure)
Return a short message based on twisted.python.failure.Failure.
tuple of (str, int) getFileLine(where)
Return the filename and line number for the given location.
  getFormatArgs(startFormat, startArgs, endFormat, endArgs, args, kwargs)
Helper function to create a format and args to use for logging.
  getLevelName(level)
Return the name of a log level.
  info(cat, format, *args)
  infoObject(object, cat, format, *args)
Log an informational message in the given category.
  init()
Initialize the logging system and parse the FLU_DEBUG environment variable.
  log(cat, format, *args)
  logObject(object, cat, format, *args)
Log a log message.
  logTwisted()
Integrate twisted's logger with Flumotion's logger.
  outputToFiles(stdout, stderr)
Redirect stdout and stderr to named files.
  registerCategory(category)
Register a given category in the debug system.
  reopenOutputFiles()
Reopens the stdout and stderr output files, as set by flumotion.common.log.outputToFiles.
  reset()
Resets the logging system, removing all log handlers.
  scrubFilename(filename)
Scrub the filename of everything before 'flumotion' and'twisted' to make them shorter.
  setFluDebug(string)
Set the FLU_DEBUG string.
  stderrHandler(level, object, category, file, line, message)
A log handler that writes to stderr.
  warning(cat, format, *args)
  warningFailure(failure, swallow)
Log a warning about a Failure.
  warningObject(object, cat, format, *args)
Log a warning message in the given category.
  _canShortcutLogging(category, level)
  _getTheFluLogObserver()

Variable Summary
int DEBUG = 4                                                                     
int ERROR = 1                                                                     
int INFO = 3                                                                     
int LOG = 5                                                                     
int WARN = 2                                                                     
NoneType __theFluLogObserver = None                                                                  
dict _categories = {}
str _FLU_DEBUG = '*:1'
bool _initialized = False
bool _initializedTwisted = False
list _log_handlers = []
list _log_handlers_limited = []
NoneType _stderr = None                                                                  
NoneType _stdout = None                                                                  

Function Details

addLogHandler(func, limited=True)

Add a custom log handler.
Parameters:
func - a function object with prototype (level, object, category, message) where level is either ERROR, WARN, INFO, DEBUG, or LOG, and the rest of the arguments are strings or None. Use getLevelName(level) to get a printable name for the log level.
           (type=a callable function)
limited - whether to automatically filter based on FLU_DEBUG
           (type=boolean)

debugObject(object, cat, format, *args)

Log a debug message in the given category.

doLog(level, object, category, format, args, where=-1, file=None, line=None)

Parameters:
where - what to log file and line number for; -1 for one frame above log.py; -2 and down for higher up; a function for a (future) code object
           (type=int or callable)
file - file to show the message as coming from, if caller knows best
           (type=str)
line - line to show the message as coming from, if caller knows best
           (type=int)
Returns:
dict of calculated variables, if they needed calculating. currently contains file and line; this prevents us from doing this work in the caller when it isn't needed because of the debug level

ellipsize(o)

Ellipsize the representation of the given object.

errorObject(object, cat, format, *args)

Log a fatal error message in the given category. This will also raise a flumotion.common.errors.SystemError.

getCategoryLevel(category)

Parameters:
category -

string

Get the debug level at which this category is being logged, adding it if it wasn't registered yet.

getExceptionMessage(exception, frame=-1, filename=None)

Return a short message based on an exception, useful for debugging. Tries to find where the exception was triggered.

getFailureMessage(failure)

Return a short message based on twisted.python.failure.Failure. Tries to find where the exception was triggered.

getFileLine(where=-1)

Return the filename and line number for the given location.

If where is a negative integer, look for the code entry in the current stack that is the given number of frames above this module. If where is a function, look for the code entry of the function.
Parameters:
where - how many frames to go back up, or function
           (type=int (negative) or function)
Returns:
tuple of (file, line)
           (type=tuple of (str, int))

getFormatArgs(startFormat, startArgs, endFormat, endArgs, args, kwargs)

Helper function to create a format and args to use for logging. This avoids needlessly interpolating variables.

getLevelName(level)

Return the name of a log level.

infoObject(object, cat, format, *args)

Log an informational message in the given category.

init()

Initialize the logging system and parse the FLU_DEBUG environment variable. Needs to be called before starting the actual application.

logObject(object, cat, format, *args)

Log a log message. Used for debugging recurring events.

logTwisted()

Integrate twisted's logger with Flumotion's logger.

This is done in a separate method because calling this imports and sets up a reactor. Since we want basic logging working before choosing a reactor, we need to separate these.

outputToFiles(stdout, stderr)

Redirect stdout and stderr to named files.

Records the file names so that a future call to reopenOutputFiles() can open the same files. Installs a SIGHUP handler that will reopen the output files.

Note that stderr is opened unbuffered, so if it shares a file with stdout then interleaved output may not appear in the order that you expect.

registerCategory(category)

Register a given category in the debug system. A level will be assigned to it based on the setting of FLU_DEBUG.

reopenOutputFiles()

Reopens the stdout and stderr output files, as set by flumotion.common.log.outputToFiles.

reset()

Resets the logging system, removing all log handlers.

scrubFilename(filename)

Scrub the filename of everything before 'flumotion' and'twisted' to make them shorter.

setFluDebug(string)

Set the FLU_DEBUG string. This controls the log output.

stderrHandler(level, object, category, file, line, message)

A log handler that writes to stderr.
Parameters:
level
           (type=string)
object
           (type=string (or None))
category
           (type=string)
message
           (type=string)

warningFailure(failure, swallow=True)

Log a warning about a Failure. Useful as an errback handler: d.addErrback(warningFailure)
Parameters:
swallow - whether to swallow the failure or not
           (type=bool)

warningObject(object, cat, format, *args)

Log a warning message in the given category. This is used for non-fatal problems.

Variable Details

DEBUG

Type:
int
Value:
4                                                                     

ERROR

Type:
int
Value:
1                                                                     

INFO

Type:
int
Value:
3                                                                     

LOG

Type:
int
Value:
5                                                                     

WARN

Type:
int
Value:
2                                                                     

__theFluLogObserver

Type:
NoneType
Value:
None                                                                  

_categories

Type:
dict
Value:
{}                                                                     

_FLU_DEBUG

Type:
str
Value:
'*:1'                                                                  

_initialized

Type:
bool
Value:
False                                                                  

_initializedTwisted

Type:
bool
Value:
False                                                                  

_log_handlers

Type:
list
Value:
[]                                                                     

_log_handlers_limited

Type:
list
Value:
[]                                                                     

_stderr

Type:
NoneType
Value:
None                                                                  

_stdout

Type:
NoneType
Value:
None                                                                  

Generated by Epydoc 2.1 on Sat Apr 14 13:20:44 2007 http://epydoc.sf.net