Belle II Software development
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.
 
void setAbortLevel (LogConfig::ELogLevel level)
 Set the abort log level.
 
void setDebugLevel (int level)
 Set the debug messaging level.
 
void setLogInfo (LogConfig::ELogLevel level, int info)
 Set the printed log information for the given level.
 
void setPackageLogConfig (const std::string &package, const LogConfig &config)
 Set LogConfig for a given package.
 
void setMaxMessageRepetitions (unsigned repetitions)
 Set maximum number of repetitions before silencing "identical" log messages.
 
LogConfig::ELogLevel getLogLevel ()
 Get the log level.
 
LogConfig::ELogLevel getAbortLevel ()
 Get the abort level.
 
int getDebugLevel ()
 Get the debug level.
 
int getLogInfo (LogConfig::ELogLevel level)
 Get the printed log information for the given level.
 
LogConfiggetPackageLogConfig (const std::string &package)
 Get the LogConfig for the given package.
 
LogConfiggetModuleLogConfig (const std::string &module)
 Get the LogConfig for the given module.
 
unsigned getMaxMessageRepetitions () const
 Get maximum number of repetitions before silencing "identical" log messages.
 
void addLogFile (const std::string &filename, bool append=false)
 Add a file as output connection.
 
void addLogConsole ()
 Add the console as output connection.
 
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.
 
void addLogUDP (const std::string &hostname, unsigned short port)
 Add a UDP server as an output connection.
 
void addLogConsole (bool color)
 Add the console as output connection.
 
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
 

Static Public Member Functions

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

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 throughout 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.

Constructor & Destructor Documentation

◆ LogPythonInterface()

LogPythonInterface ( )
inline

ctor

Definition at line 47 of file LogPythonInterface.h.

47{};

Member Function Documentation

◆ addLogConsole() [1/2]

void addLogConsole ( )

Add the console as output connection.

Color will be used automatically if supported

Definition at line 115 of file LogPythonInterface.cc.

116{
117 LogSystem::Instance().addLogConnection(new LogConnectionFilter(new LogConnectionConsole(STDOUT_FILENO)));
118}
static LogSystem & Instance()
Static method to get a reference to the LogSystem instance.
Definition LogSystem.cc:28
void addLogConnection(LogConnectionBase *logConnection)
Adds a log connection object which is used to the send the logging messages.
Definition LogSystem.cc:35

◆ addLogConsole() [2/2]

void addLogConsole ( bool color)

Add the console as output connection.

Parameters
colorFlag whether color should be used

Definition at line 120 of file LogPythonInterface.cc.

121{
122 LogSystem::Instance().addLogConnection(new LogConnectionFilter(new LogConnectionConsole(STDOUT_FILENO, color)));
123}

◆ 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 110 of file LogPythonInterface.cc.

111{
112 LogSystem::Instance().addLogConnection(new LogConnectionFilter(new LogConnectionTxtFile(filename, append)));
113}

◆ 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 100 of file LogPythonInterface.cc.

101{
102 LogSystem::Instance().addLogConnection(new LogConnectionJSON(complete));
103}

◆ 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 105 of file LogPythonInterface.cc.

106{
107 LogSystem::Instance().addLogConnection(new LogConnectionUDP(hostname, port));
108}

◆ enableErrorSummary()

void enableErrorSummary ( bool on)

Enable/Disable error summary.

Definition at line 135 of file LogPythonInterface.cc.

136{
138}
void enableErrorSummary(bool on)
enable/disable error/warning summary after successful execution and B2FATAL.
Definition LogSystem.h:190

◆ exposePythonAPI()

void exposePythonAPI ( )
static

expose python API

Expose python api.

Definition at line 192 of file LogPythonInterface.cc.

193{
194 // to avoid confusion between std::arg and boost::python::arg we want a shorthand namespace as well
195 namespace bp = boost::python;
196 scope global;
197 docstring_options options(true, true, false); //userdef, py sigs, c++ sigs
198
199 //Interface LogLevel enum
200 enum_<LogConfig::ELogLevel>("LogLevel", R"DOCSTRING(Class for all possible log levels
201
202.. attribute:: DEBUG
203
204 The lowest possible severity meant for expert only information and disabled
205 by default. In contrast to all other log levels DEBUG messages have an
206 additional numeric indication of their priority called the ``debug_level`` to
207 allow for different levels of verbosity.
208
209 The agreed values for ``debug_level`` are
210
211 * **0-9** for user code. These numbers are reserved for user analysis code and
212 may not be used by any part of basf2.
213 * **10-19** for analysis package code. The use case is that a user wants to debug
214 problems in analysis jobs with the help of experts.
215
216 * **20-29** for simulation/reconstruction code.
217 * **30-39** for core framework code.
218
219 .. note:: The default maximum debug level which will be shown when
220 running ``basf2 --debug`` without any argument for ``--debug`` is **10**
221
222
223.. attribute:: INFO
224
225 Used for informational messages which are of use for the average user but not
226 very important. Should be used very sparsely, everything which is of no
227 interest to the average user should be a debug message.
228
229.. attribute:: RESULT
230
231 Informational message which don't indicate an error condition but are more
232 important than a mere information. For example the calculated cross section
233 or the output file name.
234
235 .. deprecated:: release-01-00-00
236 use `INFO <basf2.LogLevel.INFO>` messages instead
237
238.. attribute:: WARNING
239
240 For messages which indicate something which is not correct but not fatal to
241 the processing. This should **not** be used to make informational messages
242 more prominent and they should not be ignored by the user but they are not
243 critical.
244
245.. attribute:: ERROR
246
247 For messages which indicate a clear error condition which needs to be
248 recovered. If error messages are produced before event processing is started
249 the processing will be aborted. During processing errors don't lead to a stop
250 of the processing but still indicate a problem.
251
252.. attribute:: FATAL
253
254 For errors so severe that no recovery is possible. Emitting a fatal error
255 will always stop the processing and the `B2FATAL` function is guaranteed to
256 not return.
257)DOCSTRING")
265 ;
266
267 //Interface LogInfo enum
268 enum_<LogConfig::ELogInfo>("LogInfo", R"DOCSTRING(The different fields of a log message.
269
270These fields can be used as a bitmask to configure the appearance of log messages.
271
272.. attribute:: LEVEL
273
274 The severity of the log message, one of `basf2.LogLevel`
275
276.. attribute:: MESSAGE
277
278 The actual log message
279
280.. attribute:: MODULE
281
282 The name of the module active when the message was emitted. Can be empty if
283 no module was active (before/after processing or outside of the normal event
284 loop)
285
286.. attribute:: PACKAGE
287
288 The package the code that emitted the message belongs to. This is empty for
289 messages emitted by python scripts
290
291.. attribute:: FUNCTION
292
293 The function name that emitted the message
294
295.. attribute:: FILE
296
297 The filename containing the code emitting the message
298
299.. attribute:: LINE
300
301 The line number in the file emitting the message
302)DOCSTRING")
303 .value("LEVEL", LogConfig::c_Level)
304 .value("MESSAGE", LogConfig::c_Message)
305 .value("MODULE", LogConfig::c_Module)
306 .value("PACKAGE", LogConfig::c_Package)
307 .value("FUNCTION", LogConfig::c_Function)
308 .value("FILE", LogConfig::c_File)
309 .value("LINE", LogConfig::c_Line)
310 .value("TIMESTAMP", LogConfig::c_Timestamp)
311 ;
312
313 //Interface LogConfig class
314 class_<LogConfig>("LogConfig",
315 R"(Defines logging settings (log levels and items included in each message) for a certain context, e.g. a module or package.
316
317.. seealso:: `logging.package(str) <basf2.LogPythonInterface.package>`)")
318 .def(init<bp::optional<LogConfig::ELogLevel, int> >())
319 .add_property("log_level", &LogConfig::getLogLevel, &LogConfig::setLogLevel, "set or get the current log level")
320 .add_property("debug_level", &LogConfig::getDebugLevel, &LogConfig::setDebugLevel, "set or get the current debug level")
321 .add_property("abort_level", &LogConfig::getAbortLevel, &LogConfig::setAbortLevel,
322 "set or get the severity which causes program abort")
323 .def("set_log_level", &LogConfig::setLogLevel, args("log_level"), R"DOC(
324Set the minimum log level to be shown. Messages with a log level below this value will not be shown at all.
325
326.. warning: Message with a level of `ERROR <LogLevel.ERROR>` or higher will always be shown and cannot be silenced.
327)DOC")
328 .def("set_debug_level", &LogConfig::setDebugLevel, args("debug_level"), R"DOC(
329Set the maximum debug level to be shown. Any messages with log level `DEBUG <LogLevel.DEBUG>` and a larger debug level will not be shown.
330
331.. seealso: the documentation of `DEBUG <LogLevel.DEBUG>` for suitable values
332)DOC")
333 .def("set_abort_level", &LogConfig::setAbortLevel, args("abort_level"), R"DOC(
334Set the severity which causes program abort.
335
336This can be set to a `LogLevel` which will cause the processing to be aborted if
337a message with the given level or higher is encountered. The default is
338`FATAL <LogLevel.FATAL>`. It cannot be set any higher but can be lowered.
339)DOC")
340 .def("set_info", &LogConfig::setLogInfo, args("log_level", "log_info"),
341 "set the bitmask of LogInfo members to show when printing messages for a given log level")
342 .def("get_info", &LogConfig::getLogInfo, args("log_level"),
343 "get the current bitmask of which parts of the log message will be printed for a given log level")
344 ;
345
347
348 //Interface the Interface class :)
349 class_<LogPythonInterface, std::shared_ptr<LogPythonInterface>, boost::noncopyable>("LogPythonInterface", R"(
350Logging configuration (for messages generated from C++ or Python), available as a global `basf2.logging` object in Python. See also `basf2.set_log_level()` and `basf2.set_debug_level()`.
351
352This class exposes a object called `logging <basf2.logging>` to the python interface. With
353this object it is possible to set all properties of the logging system
354directly in the steering file in a consistent manner This class also
355exposes the `LogConfig` class as well as the `LogLevel`
356and `LogInfo` enums to make setting of properties more transparent
357by using the names and not just the values. To set or get the log level,
358one can simply do:
359
360>>> logging.log_level = LogLevel.FATAL
361>>> print("Logging level set to", logging.log_level)
362FATAL
363
364This module also allows to send log messages directly from python to ease
365consistent error reporting throughout the framework
366
367>>> B2WARNING("This is a warning message")
368
369.. seealso::
370
371 For all features, see :download:`b2logging.py </framework/examples/b2logging.py>`)")
372 .add_property("log_level", &LogPythonInterface::getLogLevel, &LogPythonInterface::setLogLevel, R"DOC(
373Attribute for setting/getting the current `log level <basf2.LogLevel>`.
374Messages with a lower level are ignored.
375
376.. warning: Message with a level of `ERROR <LogLevel.ERROR>` or higher will always be shown and cannot be silenced.
377)DOC")
379 "Attribute for getting/setting the debug level. If debug messages are enabled, their level needs to be at least this high to be printed. Defaults to 100.")
381 "Attribute for setting/getting the `log level <basf2.LogLevel>` at which to abort processing. Defaults to `FATAL <LogLevel.FATAL>` but can be set to a lower level in rare cases.")
383Set the maximum amount of times log messages with the same level and message text
384(excluding variables) will be repeated before it is suppressed. Suppressed messages
385will still be counted but not shown for the remainder of the processing.
386
387This affects messages with the same text but different ref:`logging_logvariables`.
388If the same log message is repeated frequently with different variables all of
389these will be suppressed after the given amount of repetitions.
390
391.. versionadded:: release-05-00-00
392)DOC")
393
394 .def("set_package", &LogPythonInterface::setPackageLogConfig, args("package", "config"),
395 "Set `basf2.LogConfig` for given package, see also `package() <basf2.LogPythonInterface.package>`.")
396 .def("package", &LogPythonInterface::getPackageLogConfig, return_value_policy<reference_existing_object>(), args("package"),
397 R"(Get the `LogConfig` for given package to set detailed logging pararameters for this package.
398
399 >>> logging.package('svd').debug_level = 10
400 >>> logging.package('svd').set_info(LogLevel.INFO, LogInfo.LEVEL | LogInfo.MESSAGE | LogInfo.FILE)
401 )")
402 .def("module", &LogPythonInterface::getModuleLogConfig, return_value_policy<reference_existing_object>(), args("module"),
403 R"(Get the `LogConfig` for given package to set detailed logging pararameters for this module.
404
405 >>> logging.package('svd').debug_level = 10
406 >>> logging.package('svd').set_info(LogLevel.INFO, LogInfo.LEVEL | LogInfo.MESSAGE | LogInfo.FILE)
407 )")
408 .def("set_info", &LogPythonInterface::setLogInfo, args("log_level", "log_info"),
409 R"DOCSTRING(Set info to print for given log level. Should be an OR combination of `basf2.LogInfo` constants.
410As an example, to show only the level and text for all debug messages one could use
411
412>>> basf2.logging.set_info(basf2.LogLevel.DEBUG, basf2.LogInfo.LEVEL | basf2.LogInfo.MESSAGE)
413
414Parameters:
415 log_level (LogLevel): log level for which to set the display info
416 log_info (int): Bitmask of `basf2.LogInfo` constants.)DOCSTRING")
417 .def("get_info", &LogPythonInterface::getLogInfo, args("log_level"), "Get info to print for given log level.\n\n"
418 "Parameters:\n log_level (basf2.LogLevel): Log level for which to get the display info")
419 .def("add_file", &LogPythonInterface::addLogFile, (bp::arg("filename"), bp::arg("append") = false),
420 R"DOCSTRING(Write log output to given file. (In addition to existing outputs)\n\n"
421
422Parameters:
423 filename (str): Filename to to write log messages into
424 append (bool): If set to True the file will be truncated before writing new messages.)DOCSTRING")
425 .def("add_console", addLogConsole,
426 addLogConsole_overloads(args("enable_color"), "Write log output to console. (In addition to existing outputs). "
427 "If ``enable_color`` is not specified color will be enabled if supported"))
428 .def("add_json", &LogPythonInterface::addLogJSON, (bp::arg("complete_info") = false), R"DOCSTRING(
429Write log output to console, but format log messages as json objects for
430simplified parsing by other tools. Each log message will be printed as a one
431line JSON object.
432
433.. versionadded:: release-03-00-00
434
435Parameters:
436 complete_info (bool): If this is set to True the complete log information is printed regardless of the `LogInfo` setting.
437
438See Also:
439 `add_console()`, `set_info()`
440)DOCSTRING")
441 .def("add_udp", &LogPythonInterface::addLogUDP, (bp::arg("hostname"), bp::arg("port")), R"DOCSTRING(
442 Send the log output as a JSON object to the given hostname and port via UDP.
443
444.. versionadded:: release-04-00-00
445
446Parameters:
447 hostname (str): The hostname to send the message to. If it can not be resolved, an exception will be thrown.
448 port (int): The port on the host to send the message via UDP.
449
450See Also:
451 `add_json()`
452)DOCSTRING")
453 .def("terminal_supports_colors", &terminalSupportsColors, "Returns true if the terminal supports colored output")
454 .staticmethod("terminal_supports_colors")
455 .def("reset", &LogPythonInterface::reset, "Remove all configured logging outputs. "
456 "You can then configure your own via `add_file() <basf2.LogPythonInterface.add_file>` "
457 "or `add_console() <basf2.LogPythonInterface.add_console>`")
458 .def("zero_counters", &LogPythonInterface::zeroCounters, "Reset the per-level message counters.")
459 .def_readonly("log_stats", &LogPythonInterface::getLogStatistics, "Returns dictionary with message counters.")
460 .def("enable_summary", &LogPythonInterface::enableErrorSummary, args("on"),
461 "Enable or disable the error summary printed at the end of processing. "
462 "Expects one argument whether or not the summary should be shown")
463 .add_property("enable_python_logging", &LogPythonInterface::getPythonLoggingEnabled,
465Enable or disable logging via python. If this is set to true than log messages
466will be sent via `sys.stdout`. This is probably slightly slower but is useful
467when running in jupyter notebooks or when trying to redirect stdout in python
468to a buffer. This setting affects all log connections to the
469console.
470
471.. versionadded:: release-03-00-00)DOCSTRING")
472 .add_property("enable_escape_newlines", &LogPythonInterface::getEscapeNewlinesEnabled,
474Enable or disable escaping of newlines in log messages to the console. If this
475is set to true than any newline character in log messages printed to the console
476will be replaced by a "\n" to ensure that every log messages fits exactly on one line.
477
478.. versionadded:: release-04-02-00)DOCSTRING")
479 ;
480
481 //Expose Logging object
482 std::shared_ptr<LogPythonInterface> initguard{new LogPythonInterface()};
483 scope().attr("logging") = initguard;
484
485 //Add all the logging functions. To handle arbitrary keyword arguments we add
486 //them as raw functions. However it seems setting the docstring needs to be
487 //done manually in this case. So create function objects, add to namespace,
488 //set docstring ...
489
490 const std::string common_doc = R"DOCSTRING(
491All additional positional arguments are converted to strings and concatenated
492to the log message. All keyword arguments are added to the function as
493:ref:`logging_logvariables`.)DOCSTRING";
494
495 auto logDebug = raw_function(&LogPythonInterface::logDebug);
496 def("B2DEBUG", logDebug);
497 setattr(logDebug, "__doc__", "B2DEBUG(debugLevel, message, *args, **kwargs)\n\n"
498 "Print a `DEBUG <basf2.LogLevel.DEBUG>` message. "
499 "The first argument is the `debug_level <basf2.LogLevel.DEBUG>`. " +
500 common_doc);
501
502 auto logInfo = raw_function(&LogPythonInterface::logInfo);
503 def("B2INFO", logInfo);
504 setattr(logInfo, "__doc__", "B2INFO(message, *args, **kwargs)\n\n"
505 "Print a `INFO <basf2.LogLevel.INFO>` message. " + common_doc);
506
507 auto logResult = raw_function(&LogPythonInterface::logResult);
508 def("B2RESULT", logResult);
int getDebugLevel() const
Returns the configured debug messaging level.
Definition LogConfig.h:105
ELogLevel getLogLevel() const
Returns the configured log level.
Definition LogConfig.h:91
void setDebugLevel(int debugLevel)
Configure the debug messaging level.
Definition LogConfig.h:98
@ c_Error
Error: for things that went wrong and have to be fixed.
Definition LogConfig.h:30
@ c_Info
Info: for informational messages, e.g.
Definition LogConfig.h:27
@ c_Debug
Debug: for code development.
Definition LogConfig.h:26
@ c_Fatal
Fatal: for situations were the program execution can not be continued.
Definition LogConfig.h:31
@ c_Warning
Warning: for potential problems that the user should pay attention to.
Definition LogConfig.h:29
@ c_Result
Result: for informational summary messages, e.g.
Definition LogConfig.h:28
@ c_Default
Default: use globally configured log level.
Definition LogConfig.h:32
unsigned int getLogInfo(ELogLevel logLevel) const
Returns the configured log information for the given level.
Definition LogConfig.h:134
ELogLevel getAbortLevel() const
Returns the configured abort level.
Definition LogConfig.h:119
void setAbortLevel(ELogLevel abortLevel)
Configure the abort level.
Definition LogConfig.h:112
@ c_Module
Module in which the message was emitted.
Definition LogConfig.h:38
@ c_File
Source file in which the message was emitted.
Definition LogConfig.h:41
@ c_Function
Function in which the message was emitted.
Definition LogConfig.h:40
@ c_Line
Line in source file in which the message was emitted.
Definition LogConfig.h:42
@ c_Level
Log level of the message.
Definition LogConfig.h:36
@ c_Package
Package in which the message was emitted.
Definition LogConfig.h:39
@ c_Message
Log message text.
Definition LogConfig.h:37
@ c_Timestamp
Time at which the message was emitted.
Definition LogConfig.h:43
void setLogLevel(ELogLevel logLevel)
Configure the log level.
Definition LogConfig.cc:25
void setLogInfo(ELogLevel logLevel, unsigned int logInfo)
Configure the printed log information for the given level.
Definition LogConfig.h:127
static const char * logLevelToString(ELogLevel logLevelType)
Converts a log level type to a string.
Definition LogConfig.cc:42
bool getEscapeNewlinesEnabled() const
Get flag if newlines in log messages to console should be replaced by ' '`.
void setDebugLevel(int level)
Set the debug messaging level.
void setAbortLevel(LogConfig::ELogLevel level)
Set the abort log level.
int getLogInfo(LogConfig::ELogLevel level)
Get the printed log information for the given level.
boost::python::dict getLogStatistics()
return dict with log statistics
void setPackageLogConfig(const std::string &package, const LogConfig &config)
Set LogConfig for a given package.
void addLogFile(const std::string &filename, bool append=false)
Add a file as output connection.
void setPythonLoggingEnabled(bool enabled) const
Set flag if logging should be done via python sys.stdout
LogConfig::ELogLevel getAbortLevel()
Get the abort level.
bool getPythonLoggingEnabled() const
Get flag if logging should be done via python sys.stdout
LogConfig & getModuleLogConfig(const std::string &module)
Get the LogConfig for the given module.
void enableErrorSummary(bool on)
Enable/Disable error summary.
void setMaxMessageRepetitions(unsigned repetitions)
Set maximum number of repetitions before silencing "identical" log messages.
static boost::python::object logDebug(boost::python::tuple args, const boost::python::dict &kwargs)
Produce debug message.
void addLogConsole()
Add the console as output connection.
void addLogUDP(const std::string &hostname, unsigned short port)
Add a UDP server as an output connection.
void setLogLevel(LogConfig::ELogLevel level)
Set the log level.
int getDebugLevel()
Get the debug level.
void reset()
Reset logging connections.
static boost::python::object logInfo(boost::python::tuple args, const boost::python::dict &kwargs)
Produce info message.
void addLogJSON(bool complete)
Add the console as output connection but print the log messages as json objects so that they can be p...
void setLogInfo(LogConfig::ELogLevel level, int info)
Set the printed log information for the given level.
unsigned getMaxMessageRepetitions() const
Get maximum number of repetitions before silencing "identical" log messages.
void setEscapeNewlinesEnabled(bool enabled) const
Set flag if newlines in log messages to console should be replaced by ' '.
LogConfig & getPackageLogConfig(const std::string &package)
Get the LogConfig for the given package.
void zeroCounters()
Reset logging counters.
static boost::python::object logResult(boost::python::tuple args, const boost::python::dict &kwargs)
Produce result message.
LogConfig::ELogLevel getLogLevel()
Get the log level.

◆ getAbortLevel()

LogConfig::ELogLevel getAbortLevel ( )

Get the abort level.

Returns
The abort level

Definition at line 70 of file LogPythonInterface.cc.

71{
73}
LogConfig * getLogConfig()
Returns global log system configuration.
Definition LogSystem.h:78

◆ getDebugLevel()

int getDebugLevel ( )

Get the debug level.

Returns
The debug level

Definition at line 75 of file LogPythonInterface.cc.

76{
78}

◆ getEscapeNewlinesEnabled()

bool getEscapeNewlinesEnabled ( ) const

Get flag if newlines in log messages to console should be replaced by '
'`.

Definition at line 155 of file LogPythonInterface.cc.

156{
158}
static bool getEscapeNewlinesEnabled()
Check whether we want to escape newlines on console.

◆ 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 80 of file LogPythonInterface.cc.

81{
83}

◆ getLogLevel()

LogConfig::ELogLevel getLogLevel ( )

Get the log level.

Returns
The log level

Definition at line 65 of file LogPythonInterface.cc.

66{
68}

◆ getLogStatistics()

dict getLogStatistics ( )

return dict with log statistics

Return dict containing message counters.

Definition at line 161 of file LogPythonInterface.cc.

162{
163 dict returnDict;
164 const LogSystem& logSys = LogSystem::Instance();
165 for (int iLevel = 0; iLevel < LogConfig::c_Default; ++iLevel) {
166 auto logLevel = static_cast<LogConfig::ELogLevel>(iLevel);
167 returnDict[logLevel] = logSys.getMessageCounter(logLevel);
168 }
169 return returnDict;
170}
ELogLevel
Definition of the supported log levels.
Definition LogConfig.h:26
int getMessageCounter(LogConfig::ELogLevel logLevel) const
Returns the number of logging calls per log level.
Definition LogSystem.cc:158

◆ 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 95 of file LogPythonInterface.cc.

96{
98}
unsigned getMaxMessageRepetitions() const
Get maximum number of repetitions before silencing "identical" log messages.
Definition LogSystem.h:169

◆ getModuleLogConfig()

LogConfig & getModuleLogConfig ( const std::string & module)

Get the LogConfig for the given module.

Parameters
moduleThe module name
Returns
The log configuration object

Definition at line 90 of file LogPythonInterface.cc.

91{
93}
LogConfig & getModuleLogConfig(const std::string &module)
Get the log configuration for the module with the given name.
Definition LogSystem.h:105

◆ 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 85 of file LogPythonInterface.cc.

86{
88}
LogConfig & getPackageLogConfig(const std::string &package)
Get the log configuration for the package with the given name.
Definition LogSystem.h:96

◆ getPythonLoggingEnabled()

bool getPythonLoggingEnabled ( ) const

Get flag if logging should be done via python sys.stdout

Definition at line 145 of file LogPythonInterface.cc.

146{
148}
static bool getPythonLoggingEnabled()
Check whether console logging via python is enabled.

◆ 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 583 of file LogPythonInterface.cc.

583 {
584 message << pythonObjectToString(args[i]);
585 }
586 const auto cppKwArgs = pythonDictToMap(kwargs);
587 LogVariableStream lvs(message.str(), cppKwArgs);
588
589 // Now we also need to find out where the message came from: use the

◆ 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 615 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 621 of file LogPythonInterface.cc.

621{
622#ifndef LOG_NO_B2RESULT
623 dispatchMessage(LogConfig::c_Result, std::move(args), kwargs);
624#endif
625 return boost::python::object();
626}

◆ 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 591 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 599 of file LogPythonInterface.cc.

605{

◆ 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 607 of file LogPythonInterface.cc.

613{

◆ reset()

void reset ( )

Reset logging connections.

Definition at line 125 of file LogPythonInterface.cc.

126{
128}
void resetLogConnections()
Removes all log connections.
Definition LogSystem.cc:41

◆ setAbortLevel()

void setAbortLevel ( LogConfig::ELogLevel level)

Set the abort log level.

Parameters
levelThe abort log level

Definition at line 40 of file LogPythonInterface.cc.

◆ setDebugLevel()

void setDebugLevel ( int level)

Set the debug messaging level.

Parameters
levelThe debug level

Definition at line 45 of file LogPythonInterface.cc.

◆ setEscapeNewlinesEnabled()

void setEscapeNewlinesEnabled ( bool enabled) const

Set flag if newlines in log messages to console should be replaced by '
'.

Definition at line 150 of file LogPythonInterface.cc.

151{
153}
static void setEscapeNewlinesEnabled(bool enabled)
Set whether we want to escape newlines on console.

◆ 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 50 of file LogPythonInterface.cc.

51{
53}

◆ setLogLevel()

void setLogLevel ( LogConfig::ELogLevel level)

Set the log level.

Parameters
levelThe log level

Definition at line 31 of file LogPythonInterface.cc.

32{
34 if (overrideLevel != LogConfig::c_Default)
35 level = overrideLevel;
36
38}
static Environment & Instance()
Static method to get a reference to the Environment instance.
int getLogLevelOverride() const
Get log level override.

◆ 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 60 of file LogPythonInterface.cc.

61{
63}
void setMaxMessageRepetitions(unsigned repetitions)
Set maximum number of repetitions before silencing "identical" log messages.
Definition LogSystem.h:176

◆ 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 55 of file LogPythonInterface.cc.

56{
58}
void addPackageLogConfig(const std::string &package, const LogConfig &logConfig)
Add the per package log configuration.
Definition LogSystem.h:87

◆ setPythonLoggingEnabled()

void setPythonLoggingEnabled ( bool enabled) const

Set flag if logging should be done via python sys.stdout

Definition at line 140 of file LogPythonInterface.cc.

141{
143}
static void setPythonLoggingEnabled(bool enabled)
Set whether console logging via python is enabled.

◆ zeroCounters()

void zeroCounters ( )

Reset logging counters.

Definition at line 130 of file LogPythonInterface.cc.

131{
133}
void resetMessageCounter()
Resets the message counter and error log by setting all message counts to 0.
Definition LogSystem.cc:147

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