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, verbose=True)
Configures the logging module.
source code
 
SetupToolLogging(debug, verbose, threadname=False, toolname=None, logfile=pathutils.LOG_TOOLS)
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, constants, compat, pathutils


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, verbose=True)

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)
  • verbose (boolean) - whether to log at 'info' level already (logfile logging only)
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, toolname=None, logfile=pathutils.LOG_TOOLS)

source code 

Configures the logging module for tools.

All log messages are sent to the tools.log logfile.

Parameters:
  • toolname (string) - name of the tool that's logging
  • debug (boolean) - Disable log message filtering
  • verbose (boolean) - Enable verbose log messages
  • threadname (boolean) - Whether to include thread name in output
  • logfile (string) - the path of the log file to use, use "None" for tools which don't necessarily run on Ganeti nodes (and thus don't have the Ganeti log directory).