Package flumotion :: Package common :: Module log
[hide private]

Module log

source code

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 [hide private]
  Loggable
Base class for objects that want to be able to log messages with different level of severity.
  FluLogObserver
Twisted log observer that integrates with Flumotion's logging.
Functions [hide private]
 
getLevelName(level)
Return the name of a log level.
source code
 
registerCategory(category)
Register a given category in the debug system.
source code
 
getCategoryLevel(category) source code
 
_canShortcutLogging(category, level) source code
 
scrubFilename(filename)
Scrub the filename of everything before 'flumotion' and'twisted' to make them shorter.
source code
tuple of (str, int)
getFileLine(where=-1)
Return the filename and line number for the given location.
source code
 
ellipsize(o)
Ellipsize the representation of the given object.
source code
 
getFormatArgs(startFormat, startArgs, endFormat, endArgs, args, kwargs)
Helper function to create a format and args to use for logging.
source code
 
doLog(level, object, category, format, args, where=-1, file=None, line=None)
Returns: dict of calculated variables, if they needed calculating.
source code
 
errorObject(object, cat, format, *args)
Log a fatal error message in the given category.
source code
 
warningObject(object, cat, format, *args)
Log a warning message in the given category.
source code
 
infoObject(object, cat, format, *args)
Log an informational message in the given category.
source code
 
debugObject(object, cat, format, *args)
Log a debug message in the given category.
source code
 
logObject(object, cat, format, *args)
Log a log message.
source code
 
error(cat, format, *args) source code
 
warning(cat, format, *args) source code
 
info(cat, format, *args) source code
 
debug(cat, format, *args) source code
 
log(cat, format, *args) source code
 
warningFailure(failure, swallow=True)
Log a warning about a Failure.
source code
 
_getTheFluLogObserver() source code
 
stderrHandler(level, object, category, file, line, message)
A log handler that writes to stderr.
source code
 
addLogHandler(func, limited=True)
Add a custom log handler.
source code
 
init()
Initialize the logging system and parse the FLU_DEBUG environment variable.
source code
 
reopenOutputFiles()
Reopens the stdout and stderr output files, as set by flumotion.common.log.outputToFiles.
source code
 
outputToFiles(stdout, stderr)
Redirect stdout and stderr to named files.
source code
 
logTwisted()
Integrate twisted's logger with Flumotion's logger.
source code
 
reset()
Resets the logging system, removing all log handlers.
source code
 
setFluDebug(string)
Set the FLU_DEBUG string.
source code
 
getExceptionMessage(exception, frame=-1, filename=None)
Return a short message based on an exception, useful for debugging.
source code
 
getFailureMessage(failure)
Return a short message based on twisted.python.failure.Failure.
source code
Variables [hide private]
  _FLU_DEBUG = '*:1'
  _categories = {}
  _log_handlers = []
  _log_handlers_limited = []
  _initialized = False
  ERROR = 1
  WARN = 2
  INFO = 3
  DEBUG = 4
  LOG = 5
  __theFluLogObserver = None
  _stdout = None
  _stderr = None
  _initializedTwisted = False
Function Details [hide private]

registerCategory(category)

source code 

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

getCategoryLevel(category)

source code 
Parameters:
  • category - string

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

getFileLine(where=-1)

source code 

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 (int (negative) or function) - how many frames to go back up, or function
Returns: tuple of (str, int)
tuple of (file, line)

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

source code 

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

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

source code 
Parameters:
  • where (int or callable) - 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
  • file (str) - file to show the message as coming from, if caller knows best
  • line (int) - line to show the message as coming from, if caller knows best
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

errorObject(object, cat, format, *args)

source code 

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

warningObject(object, cat, format, *args)

source code 

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

logObject(object, cat, format, *args)

source code 

Log a log message. Used for debugging recurring events.

warningFailure(failure, swallow=True)

source code 

Log a warning about a Failure. Useful as an errback handler: d.addErrback(warningFailure)

Parameters:
  • swallow (bool) - whether to swallow the failure or not

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

source code 

A log handler that writes to stderr.

Parameters:
  • category (string)
  • message (string)
  • object (string (or None))
  • level (string)

addLogHandler(func, limited=True)

source code 

Add a custom log handler.

Parameters:
  • func (a callable function) - 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.
  • limited (boolean) - whether to automatically filter based on FLU_DEBUG

init()

source code 

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

outputToFiles(stdout, stderr)

source code 

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.

logTwisted()

source code 

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.

setFluDebug(string)

source code 

Set the FLU_DEBUG string. This controls the log output.

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

source code 

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

getFailureMessage(failure)

source code 

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