Package ganeti :: Package utils :: Module log
[hide private]
[frames] | no frames]

Module log

source code

Utility functions for logging.

Classes [hide private]
  _ReopenableLogHandler
Log handler with ability to reopen log file on request.
Functions [hide private]
 
_LogErrorsToConsole(base)
Create wrapper class writing errors to console.
source code
 
_GetLogFormatter(program, multithreaded, debug, syslog)
Build log formatter.
source code
 
_ReopenLogFiles(handlers)
Wrapper for reopening all log handler's files in a sequence.
source code
callable
SetupLogging(logfile, program, debug=0, stderr_logging=False, multithreaded=False, syslog=constants.SYSLOG_USAGE, console_logging=False, root_logger=None)
Configures the logging module.
source code
 
SetupToolLogging(debug, verbose, threadname=False, _root_logger=None, _stream=None)
Configures the logging module for tools.
source code
Variables [hide private]
  _LogHandler = _LogErrorsToConsole(_ReopenableLogHandler)
Custom log handler for writing to console with a reopenable handler

Imports: os, logging, StringIO, constants, compat


Function Details [hide private]

_LogErrorsToConsole(base)

source code 

Create wrapper class writing errors to console.

This needs to be in a function for unittesting.

_GetLogFormatter(program, multithreaded, debug, syslog)

source code 

Build log formatter.

Parameters:
  • program - Program name
  • multithreaded - Whether to add thread name to log messages
  • debug - Whether to enable debug messages
  • syslog - Whether the formatter will be used for syslog

SetupLogging(logfile, program, debug=0, stderr_logging=False, multithreaded=False, syslog=constants.SYSLOG_USAGE, console_logging=False, root_logger=None)

source code 

Configures the logging module.

Parameters:
  • logfile (str) - the filename to which we should log
  • program (str) - the name under which we should log messages
  • debug (integer) - if greater than zero, enable debug messages, otherwise only those at INFO and above level
  • stderr_logging (boolean) - whether we should also log to the standard error
  • multithreaded (boolean) - if True, will add the thread name to the log file
  • syslog (string) - one of 'no', 'yes', 'only':
    • if no, syslog is not used
    • if yes, syslog is used (in addition to file-logging)
    • if only, only syslog is used
  • console_logging (boolean) - if True, will use a FileHandler which falls back to the system console if logging fails
  • root_logger (logging.Logger) - Root logger to use (for unittests)
Returns: callable
Function reopening all open log files when called
Raises:
  • EnvironmentError - if we can't open the log file and syslog/stderr logging is disabled

SetupToolLogging(debug, verbose, threadname=False, _root_logger=None, _stream=None)

source code 

Configures the logging module for tools.

All log messages are sent to stderr.

Parameters:
  • debug (boolean) - Disable log message filtering
  • verbose (boolean) - Enable verbose log messages
  • threadname (boolean) - Whether to include thread name in output