Belle II Software  release-08-01-10
LogPythonInterface Class Reference

Thin wrapper to expose a usable interface to the logging framework in python. More...

#include <LogPythonInterface.h>

Public Member Functions

 LogPythonInterface ()
 ctor
 
void setLogLevel (LogConfig::ELogLevel level)
 Set the log level. More...
 
void setAbortLevel (LogConfig::ELogLevel level)
 Set the abort log level. More...
 
void setDebugLevel (int level)
 Set the debug messaging level. More...
 
void setLogInfo (LogConfig::ELogLevel level, int info)
 Set the printed log information for the given level. More...
 
void setPackageLogConfig (const std::string &package, const LogConfig &config)
 Set LogConfig for a given package. More...
 
void setMaxMessageRepetitions (unsigned repetitions)
 Set maximum number of repetitions before silencing "identical" log messages. More...
 
LogConfig::ELogLevel getLogLevel ()
 Get the log level. More...
 
LogConfig::ELogLevel getAbortLevel ()
 Get the abort level. More...
 
int getDebugLevel ()
 Get the debug level. More...
 
int getLogInfo (LogConfig::ELogLevel level)
 Get the printed log information for the given level. More...
 
LogConfiggetPackageLogConfig (const std::string &package)
 Get the LogConfig for the given package. More...
 
unsigned getMaxMessageRepetitions () const
 Get maximum number of repetitions before silencing "identical" log messages. More...
 
void addLogFile (const std::string &filename, bool append=false)
 Add a file as output connection. More...
 
void addLogConsole ()
 Add the console as output connection. More...
 
void addLogJSON (bool complete)
 Add the console as output connection but print the log messages as json objects so that they can be parsed easily. More...
 
void addLogUDP (const std::string &hostname, unsigned short port)
 Add a UDP server as an output connection. More...
 
void addLogConsole (bool color)
 Add the console as output connection. More...
 
void reset ()
 Reset logging connections.
 
void zeroCounters ()
 Reset logging counters.
 
void enableErrorSummary (bool on)
 Enable/Disable error summary.
 
void setPythonLoggingEnabled (bool enabled) const
 Set flag if logging should be done via python sys.stdout
 
bool getPythonLoggingEnabled () const
 Get flag if logging should be done via python sys.stdout
 
void setEscapeNewlinesEnabled (bool enabled) const
 Set flag if newlines in log messages to console should be replaced by '
'.
 
bool getEscapeNewlinesEnabled () const
 Get flag if newlines in log messages to console should be replaced by '
'`.
 
boost::python::dict getLogStatistics ()
 return dict with log statistics More...
 

Static Public Member Functions

static boost::python::object logDebug (boost::python::tuple args, const boost::python::dict &kwargs)
 Produce debug message. More...
 
static boost::python::object logInfo (boost::python::tuple args, const boost::python::dict &kwargs)
 Produce info message. More...
 
static boost::python::object logResult (boost::python::tuple args, const boost::python::dict &kwargs)
 Produce result message. More...
 
static boost::python::object logWarning (boost::python::tuple args, const boost::python::dict &kwargs)
 Produce warning message. More...
 
static boost::python::object logError (boost::python::tuple args, const boost::python::dict &kwargs)
 Produce error message. More...
 
static boost::python::object logFatal (boost::python::tuple args, const boost::python::dict &kwargs)
 Produce fatal message. More...
 
static void exposePythonAPI ()
 expose python API More...
 

Detailed Description

Thin wrapper to expose a usable interface to the logging framework in python.

This class exposes a object called "logging" to the python interface. With this object it is possible to set all properties of the logging system directly in the steering file in a consistent manner This class also exposes the LogConfig class as well as the LogConfig::ELogLevel and LogConfig::ELogInfo enums to make setting of properties more transparent by using the names and not just the values. To set or get the log level, one can simply do:

logging.log_level = LogLevel.FATAL print "Logging level set to", logging.log_level

This module also allows to send log messages directly from python to ease consistent error reporting througout the framework

B2WARNING("This is a warning message");

For all features, see b2logging.py in the framework/examples folder

Definition at line 44 of file LogPythonInterface.h.

Member Function Documentation

◆ addLogConsole() [1/2]

void addLogConsole ( )

Add the console as output connection.

Color will be used automatically if supported

Definition at line 111 of file LogPythonInterface.cc.

112 {
114 }
Implements a log connection to an IO Stream.
Implements a log connection that filters repeated messages.
static LogSystem & Instance()
Static method to get a reference to the LogSystem instance.
Definition: LogSystem.cc:31
void addLogConnection(LogConnectionBase *logConnection)
Adds a log connection object which is used to the send the logging messages.
Definition: LogSystem.cc:38

◆ addLogConsole() [2/2]

void addLogConsole ( bool  color)

Add the console as output connection.

Parameters
colorFlag whether color should be used

Definition at line 116 of file LogPythonInterface.cc.

◆ addLogFile()

void addLogFile ( const std::string &  filename,
bool  append = false 
)

Add a file as output connection.

Parameters
filenameThe text file name
appendFlag whether output should be appended to an existing file

Definition at line 106 of file LogPythonInterface.cc.

◆ addLogJSON()

void addLogJSON ( bool  complete)

Add the console as output connection but print the log messages as json objects so that they can be parsed easily.

Parameters
completeif true ignore the log info configuration and print all parts of the log message.

Definition at line 96 of file LogPythonInterface.cc.

◆ addLogUDP()

void addLogUDP ( const std::string &  hostname,
unsigned short  port 
)

Add a UDP server as an output connection.

Parameters
hostnamethe hostname of the UDP server. Will throw an exception if it can not be resolved.
portthe port to connect to

Definition at line 101 of file LogPythonInterface.cc.

◆ exposePythonAPI()

void exposePythonAPI ( )
static

expose python API

Expose python api.

Definition at line 188 of file LogPythonInterface.cc.

◆ getAbortLevel()

LogConfig::ELogLevel getAbortLevel ( )

Get the abort level.

Returns
The abort level

Definition at line 71 of file LogPythonInterface.cc.

◆ getDebugLevel()

int getDebugLevel ( )

Get the debug level.

Returns
The debug level

Definition at line 76 of file LogPythonInterface.cc.

◆ getLogInfo()

int getLogInfo ( LogConfig::ELogLevel  level)

Get the printed log information for the given level.

Parameters
levelThe log level
Returns
The log information that should be printed (see LogConfig::ELogInfo)

Definition at line 81 of file LogPythonInterface.cc.

◆ getLogLevel()

LogConfig::ELogLevel getLogLevel ( )

Get the log level.

Returns
The log level

Definition at line 66 of file LogPythonInterface.cc.

◆ getLogStatistics()

dict getLogStatistics ( )

return dict with log statistics

Return dict containing message counters.

Definition at line 157 of file LogPythonInterface.cc.

◆ getMaxMessageRepetitions()

unsigned getMaxMessageRepetitions ( ) const

Get maximum number of repetitions before silencing "identical" log messages.

Identity only checks for log level and message content (excluding variables)

Definition at line 91 of file LogPythonInterface.cc.

◆ getPackageLogConfig()

LogConfig & getPackageLogConfig ( const std::string &  package)

Get the LogConfig for the given package.

Parameters
packageThe package name
Returns
The log configuration object

Definition at line 86 of file LogPythonInterface.cc.

◆ logDebug()

boost::python::object logDebug ( boost::python::tuple  args,
const boost::python::dict &  kwargs 
)
static

Produce debug message.

Parameters
argspositional arguments, concatenated to form message
kwargskeyword arguments to be converted to log variables

Definition at line 577 of file LogPythonInterface.cc.

◆ logError()

boost::python::object logError ( boost::python::tuple  args,
const boost::python::dict &  kwargs 
)
static

Produce error message.

Parameters
argspositional arguments, concatenated to form message
kwargskeyword arguments to be converted to log variables

Definition at line 609 of file LogPythonInterface.cc.

◆ logFatal()

boost::python::object logFatal ( boost::python::tuple  args,
const boost::python::dict &  kwargs 
)
static

Produce fatal message.

Parameters
argspositional arguments, concatenated to form message
kwargskeyword arguments to be converted to log variables

Definition at line 615 of file LogPythonInterface.cc.

◆ logInfo()

boost::python::object logInfo ( boost::python::tuple  args,
const boost::python::dict &  kwargs 
)
static

Produce info message.

Parameters
argspositional arguments, concatenated to form message
kwargskeyword arguments to be converted to log variables

Definition at line 585 of file LogPythonInterface.cc.

◆ logResult()

boost::python::object logResult ( boost::python::tuple  args,
const boost::python::dict &  kwargs 
)
static

Produce result message.

Parameters
argspositional arguments, concatenated to form message
kwargskeyword arguments to be converted to log variables

Definition at line 593 of file LogPythonInterface.cc.

◆ logWarning()

boost::python::object logWarning ( boost::python::tuple  args,
const boost::python::dict &  kwargs 
)
static

Produce warning message.

Parameters
argspositional arguments, concatenated to form message
kwargskeyword arguments to be converted to log variables

Definition at line 601 of file LogPythonInterface.cc.

◆ setAbortLevel()

void setAbortLevel ( LogConfig::ELogLevel  level)

Set the abort log level.

Parameters
levelThe abort log level

Definition at line 41 of file LogPythonInterface.cc.

◆ setDebugLevel()

void setDebugLevel ( int  level)

Set the debug messaging level.

Parameters
levelThe debug level

Definition at line 46 of file LogPythonInterface.cc.

◆ setLogInfo()

void setLogInfo ( LogConfig::ELogLevel  level,
int  info 
)

Set the printed log information for the given level.

Parameters
levelThe log level
infoThe log information that should be printed

Definition at line 51 of file LogPythonInterface.cc.

◆ setLogLevel()

void setLogLevel ( LogConfig::ELogLevel  level)

Set the log level.

Parameters
levelThe log level

Definition at line 32 of file LogPythonInterface.cc.

◆ setMaxMessageRepetitions()

void setMaxMessageRepetitions ( unsigned  repetitions)

Set maximum number of repetitions before silencing "identical" log messages.

Identity only checks for log level and message content (excluding variables)

Definition at line 61 of file LogPythonInterface.cc.

◆ setPackageLogConfig()

void setPackageLogConfig ( const std::string &  package,
const LogConfig config 
)

Set LogConfig for a given package.

Parameters
packageThe package name
configThe log configuration object

Definition at line 56 of file LogPythonInterface.cc.


The documentation for this class was generated from the following files: