Belle II Software light-2607-kasei
LogPythonInterface.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <boost/python.hpp>
10
11#include <framework/pybasf2/LogPythonInterface.h>
12
13#include <framework/logging/LogConnectionFilter.h>
14#include <framework/logging/LogConnectionTxtFile.h>
15#include <framework/logging/LogConnectionJSON.h>
16#include <framework/logging/LogConnectionUDP.h>
17#include <framework/logging/LogConnectionConsole.h>
18#include <framework/logging/LogVariableStream.h>
19#include <framework/logging/LogSystem.h>
20
21#include <framework/core/Environment.h>
22
23#include <string>
24#include <map>
25#include <utility>
26
27using namespace std;
28using namespace Belle2;
29using namespace boost::python;
30
32{
33 auto overrideLevel = (LogConfig::ELogLevel)Environment::Instance().getLogLevelOverride();
34 if (overrideLevel != LogConfig::c_Default)
35 level = overrideLevel;
36
38}
39
44
49
54
55void LogPythonInterface::setPackageLogConfig(const std::string& package, const LogConfig& config)
56{
58}
59
64
69
74
79
84
86{
88}
89
91{
93}
94
99
104
105void LogPythonInterface::addLogUDP(const std::string& hostname, unsigned short port)
106{
108}
109
110void LogPythonInterface::addLogFile(const std::string& filename, bool append)
111{
113}
114
119
124
129
134
139
144
149
154
159
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}
171
172namespace {
173#if !defined(__GNUG__) || defined(__ICC)
174#else
175#pragma GCC diagnostic push
176#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
177#endif
179 // cppcheck-suppress unknownMacro
180 BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(addLogConsole_overloads, addLogConsole, 0, 1)
181#if !defined(__GNUG__) || defined(__ICC)
182#else
183#pragma GCC diagnostic pop
184#endif
185
186 bool terminalSupportsColors()
187 {
189 }
190}
191
194{
195 // to avoid confusion between std::arg and boost::python::arg we want a shorthand namespace as well
196 namespace bp = boost::python;
197 scope global;
198 docstring_options options(true, true, false); //userdef, py sigs, c++ sigs
199
200 //Interface LogLevel enum
201 enum_<LogConfig::ELogLevel>("LogLevel", R"DOCSTRING(Class for all possible log levels
202
203.. attribute:: DEBUG
204
205 The lowest possible severity meant for expert only information and disabled
206 by default. In contrast to all other log levels DEBUG messages have an
207 additional numeric indication of their priority called the ``debug_level`` to
208 allow for different levels of verbosity.
209
210 The agreed values for ``debug_level`` are
211
212 * **0-9** for user code. These numbers are reserved for user analysis code and
213 may not be used by any part of basf2.
214 * **10-19** for analysis package code. The use case is that a user wants to debug
215 problems in analysis jobs with the help of experts.
216
217 * **20-29** for simulation/reconstruction code.
218 * **30-39** for core framework code.
219
220 .. note:: The default maximum debug level which will be shown when
221 running ``basf2 --debug`` without any argument for ``--debug`` is **10**
222
223
224.. attribute:: INFO
225
226 Used for informational messages which are of use for the average user but not
227 very important. Should be used very sparsely, everything which is of no
228 interest to the average user should be a debug message.
229
230.. attribute:: RESULT
231
232 Informational message which don't indicate an error condition but are more
233 important than a mere information. For example the calculated cross section
234 or the output file name.
235
236 .. deprecated:: release-01-00-00
237 use `INFO <basf2.LogLevel.INFO>` messages instead
238
239.. attribute:: WARNING
240
241 For messages which indicate something which is not correct but not fatal to
242 the processing. This should **not** be used to make informational messages
243 more prominent and they should not be ignored by the user but they are not
244 critical.
245
246.. attribute:: ERROR
247
248 For messages which indicate a clear error condition which needs to be
249 recovered. If error messages are produced before event processing is started
250 the processing will be aborted. During processing errors don't lead to a stop
251 of the processing but still indicate a problem.
252
253.. attribute:: FATAL
254
255 For errors so severe that no recovery is possible. Emitting a fatal error
256 will always stop the processing and the `B2FATAL` function is guaranteed to
257 not return.
258)DOCSTRING")
266 ;
267
268 //Interface LogInfo enum
269 enum_<LogConfig::ELogInfo>("LogInfo", R"DOCSTRING(The different fields of a log message.
270
271These fields can be used as a bitmask to configure the appearance of log messages.
272
273.. attribute:: LEVEL
274
275 The severity of the log message, one of `basf2.LogLevel`
276
277.. attribute:: MESSAGE
278
279 The actual log message
280
281.. attribute:: MODULE
282
283 The name of the module active when the message was emitted. Can be empty if
284 no module was active (before/after processing or outside of the normal event
285 loop)
286
287.. attribute:: PACKAGE
288
289 The package the code that emitted the message belongs to. This is empty for
290 messages emitted by python scripts
291
292.. attribute:: FUNCTION
293
294 The function name that emitted the message
295
296.. attribute:: FILE
297
298 The filename containing the code emitting the message
299
300.. attribute:: LINE
301
302 The line number in the file emitting the message
303)DOCSTRING")
304 .value("LEVEL", LogConfig::c_Level)
305 .value("MESSAGE", LogConfig::c_Message)
306 .value("MODULE", LogConfig::c_Module)
307 .value("PACKAGE", LogConfig::c_Package)
308 .value("FUNCTION", LogConfig::c_Function)
309 .value("FILE", LogConfig::c_File)
310 .value("LINE", LogConfig::c_Line)
311 .value("TIMESTAMP", LogConfig::c_Timestamp)
312 ;
313
314 //Interface LogConfig class
315 class_<LogConfig>("LogConfig",
316 R"(Defines logging settings (log levels and items included in each message) for a certain context, e.g. a module or package.
317
318.. seealso:: `logging.package(str) <basf2.LogPythonInterface.package>`)")
319 .def(init<bp::optional<LogConfig::ELogLevel, int> >())
320 .add_property("log_level", &LogConfig::getLogLevel, &LogConfig::setLogLevel, "set or get the current log level")
321 .add_property("debug_level", &LogConfig::getDebugLevel, &LogConfig::setDebugLevel, "set or get the current debug level")
322 .add_property("abort_level", &LogConfig::getAbortLevel, &LogConfig::setAbortLevel,
323 "set or get the severity which causes program abort")
324 .def("set_log_level", &LogConfig::setLogLevel, args("log_level"), R"DOC(
325Set the minimum log level to be shown. Messages with a log level below this value will not be shown at all.
326
327.. warning: Message with a level of `ERROR <LogLevel.ERROR>` or higher will always be shown and cannot be silenced.
328)DOC")
329 .def("set_debug_level", &LogConfig::setDebugLevel, args("debug_level"), R"DOC(
330Set the maximum debug level to be shown. Any messages with log level `DEBUG <LogLevel.DEBUG>` and a larger debug level will not be shown.
331
332.. seealso: the documentation of `DEBUG <LogLevel.DEBUG>` for suitable values
333)DOC")
334 .def("set_abort_level", &LogConfig::setAbortLevel, args("abort_level"), R"DOC(
335Set the severity which causes program abort.
336
337This can be set to a `LogLevel` which will cause the processing to be aborted if
338a message with the given level or higher is encountered. The default is
339`FATAL <LogLevel.FATAL>`. It cannot be set any higher but can be lowered.
340)DOC")
341 .def("set_info", &LogConfig::setLogInfo, args("log_level", "log_info"),
342 "set the bitmask of LogInfo members to show when printing messages for a given log level")
343 .def("get_info", &LogConfig::getLogInfo, args("log_level"),
344 "get the current bitmask of which parts of the log message will be printed for a given log level")
345 ;
346
348
349 //Interface the Interface class :)
350 class_<LogPythonInterface, std::shared_ptr<LogPythonInterface>, boost::noncopyable>("LogPythonInterface", R"(
351Logging 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()`.
352
353This class exposes a object called `logging <basf2.logging>` to the python interface. With
354this object it is possible to set all properties of the logging system
355directly in the steering file in a consistent manner This class also
356exposes the `LogConfig` class as well as the `LogLevel`
357and `LogInfo` enums to make setting of properties more transparent
358by using the names and not just the values. To set or get the log level,
359one can simply do:
360
361>>> logging.log_level = LogLevel.FATAL
362>>> print("Logging level set to", logging.log_level)
363FATAL
364
365This module also allows to send log messages directly from python to ease
366consistent error reporting throughout the framework
367
368>>> B2WARNING("This is a warning message")
369
370.. seealso::
371
372 For all features, see :download:`b2logging.py </framework/examples/b2logging.py>`)")
373 .add_property("log_level", &LogPythonInterface::getLogLevel, &LogPythonInterface::setLogLevel, R"DOC(
374Attribute for setting/getting the current `log level <basf2.LogLevel>`.
375Messages with a lower level are ignored.
376
377.. warning: Message with a level of `ERROR <LogLevel.ERROR>` or higher will always be shown and cannot be silenced.
378)DOC")
380 "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.")
382 "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.")
384Set the maximum amount of times log messages with the same level and message text
385(excluding variables) will be repeated before it is suppressed. Suppressed messages
386will still be counted but not shown for the remainder of the processing.
387
388This affects messages with the same text but different ref:`logging_logvariables`.
389If the same log message is repeated frequently with different variables all of
390these will be suppressed after the given amount of repetitions.
391
392.. versionadded:: release-05-00-00
393)DOC")
394
395 .def("set_package", &LogPythonInterface::setPackageLogConfig, args("package", "config"),
396 "Set `basf2.LogConfig` for given package, see also `package() <basf2.LogPythonInterface.package>`.")
397 .def("package", &LogPythonInterface::getPackageLogConfig, return_value_policy<reference_existing_object>(), args("package"),
398 R"(Get the `LogConfig` for given package to set detailed logging pararameters for this package.
399
400 >>> logging.package('svd').debug_level = 10
401 >>> logging.package('svd').set_info(LogLevel.INFO, LogInfo.LEVEL | LogInfo.MESSAGE | LogInfo.FILE)
402 )")
403 .def("module", &LogPythonInterface::getModuleLogConfig, return_value_policy<reference_existing_object>(), args("module"),
404 R"(Get the `LogConfig` for given package to set detailed logging pararameters for this module.
405
406 >>> logging.package('svd').debug_level = 10
407 >>> logging.package('svd').set_info(LogLevel.INFO, LogInfo.LEVEL | LogInfo.MESSAGE | LogInfo.FILE)
408 )")
409 .def("set_info", &LogPythonInterface::setLogInfo, args("log_level", "log_info"),
410 R"DOCSTRING(Set info to print for given log level. Should be an OR combination of `basf2.LogInfo` constants.
411As an example, to show only the level and text for all debug messages one could use
412
413>>> basf2.logging.set_info(basf2.LogLevel.DEBUG, basf2.LogInfo.LEVEL | basf2.LogInfo.MESSAGE)
414
415Parameters:
416 log_level (LogLevel): log level for which to set the display info
417 log_info (int): Bitmask of `basf2.LogInfo` constants.)DOCSTRING")
418 .def("get_info", &LogPythonInterface::getLogInfo, args("log_level"), "Get info to print for given log level.\n\n"
419 "Parameters:\n log_level (basf2.LogLevel): Log level for which to get the display info")
420 .def("add_file", &LogPythonInterface::addLogFile, (bp::arg("filename"), bp::arg("append") = false),
421 R"DOCSTRING(Write log output to given file. (In addition to existing outputs)\n\n"
422
423Parameters:
424 filename (str): Filename to to write log messages into
425 append (bool): If set to True the file will be truncated before writing new messages.)DOCSTRING")
426 .def("add_console", addLogConsole,
427 addLogConsole_overloads(args("enable_color"), "Write log output to console. (In addition to existing outputs). "
428 "If ``enable_color`` is not specified color will be enabled if supported"))
429 .def("add_json", &LogPythonInterface::addLogJSON, (bp::arg("complete_info") = false), R"DOCSTRING(
430Write log output to console, but format log messages as json objects for
431simplified parsing by other tools. Each log message will be printed as a one
432line JSON object.
433
434.. versionadded:: release-03-00-00
435
436Parameters:
437 complete_info (bool): If this is set to True the complete log information is printed regardless of the `LogInfo` setting.
438
439See Also:
440 `add_console()`, `set_info()`
441)DOCSTRING")
442 .def("add_udp", &LogPythonInterface::addLogUDP, (bp::arg("hostname"), bp::arg("port")), R"DOCSTRING(
443 Send the log output as a JSON object to the given hostname and port via UDP.
444
445.. versionadded:: release-04-00-00
446
447Parameters:
448 hostname (str): The hostname to send the message to. If it can not be resolved, an exception will be thrown.
449 port (int): The port on the host to send the message via UDP.
450
451See Also:
452 `add_json()`
453)DOCSTRING")
454 .def("terminal_supports_colors", &terminalSupportsColors, "Returns true if the terminal supports colored output")
455 .staticmethod("terminal_supports_colors")
456 .def("reset", &LogPythonInterface::reset, "Remove all configured logging outputs. "
457 "You can then configure your own via `add_file() <basf2.LogPythonInterface.add_file>` "
458 "or `add_console() <basf2.LogPythonInterface.add_console>`")
459 .def("zero_counters", &LogPythonInterface::zeroCounters, "Reset the per-level message counters.")
460 .def_readonly("log_stats", &LogPythonInterface::getLogStatistics, "Returns dictionary with message counters.")
461 .def("enable_summary", &LogPythonInterface::enableErrorSummary, args("on"),
462 "Enable or disable the error summary printed at the end of processing. "
463 "Expects one argument whether or not the summary should be shown")
464 .add_property("enable_python_logging", &LogPythonInterface::getPythonLoggingEnabled,
466Enable or disable logging via python. If this is set to true than log messages
467will be sent via `sys.stdout`. This is probably slightly slower but is useful
468when running in jupyter notebooks or when trying to redirect stdout in python
469to a buffer. This setting affects all log connections to the
470console.
471
472.. versionadded:: release-03-00-00)DOCSTRING")
473 .add_property("enable_escape_newlines", &LogPythonInterface::getEscapeNewlinesEnabled,
475Enable or disable escaping of newlines in log messages to the console. If this
476is set to true than any newline character in log messages printed to the console
477will be replaced by a "\n" to ensure that every log messages fits exactly on one line.
478
479.. versionadded:: release-04-02-00)DOCSTRING")
480 ;
481
482 //Expose Logging object
483 std::shared_ptr<LogPythonInterface> initguard{new LogPythonInterface()};
484 scope().attr("logging") = initguard;
485
486 //Add all the logging functions. To handle arbitrary keyword arguments we add
487 //them as raw functions. However it seems setting the docstring needs to be
488 //done manually in this case. So create function objects, add to namespace,
489 //set docstring ...
490
491 const std::string common_doc = R"DOCSTRING(
492All additional positional arguments are converted to strings and concatenated
493to the log message. All keyword arguments are added to the function as
494:ref:`logging_logvariables`.)DOCSTRING";
495
496 auto logDebug = raw_function(&LogPythonInterface::logDebug);
497 def("B2DEBUG", logDebug);
498 setattr(logDebug, "__doc__", "B2DEBUG(debugLevel, message, *args, **kwargs)\n\n"
499 "Print a `DEBUG <basf2.LogLevel.DEBUG>` message. "
500 "The first argument is the `debug_level <basf2.LogLevel.DEBUG>`. " +
501 common_doc);
502
503 auto logInfo = raw_function(&LogPythonInterface::logInfo);
504 def("B2INFO", logInfo);
505 setattr(logInfo, "__doc__", "B2INFO(message, *args, **kwargs)\n\n"
506 "Print a `INFO <basf2.LogLevel.INFO>` message. " + common_doc);
507
508 auto logResult = raw_function(&LogPythonInterface::logResult);
509 def("B2RESULT", logResult);
510 setattr(logResult, "__doc__", "B2RESULT(message, *args, **kwargs)\n\n"
511 "Print a `RESULT <basf2.LogLevel.RESULT>` message. " + common_doc
512 + "\n\n.. deprecated:: release-01-00-00\n use `B2INFO()` instead");
513
514 auto logWarning = raw_function(&LogPythonInterface::logWarning);
515 def("B2WARNING", logWarning);
516 setattr(logWarning, "__doc__", "B2WARNING(message, *args, **kwargs)\n\n"
517 "Print a `WARNING <basf2.LogLevel.WARNING>` message. " + common_doc);
518
519 auto logError = raw_function(&LogPythonInterface::logError);
520 def("B2ERROR", logError);
521 setattr(logError, "__doc__", "B2ERROR(message, *args, **kwargs)\n\n"
522 "Print a `ERROR <basf2.LogLevel.ERROR>` message. " + common_doc);
523
524 auto logFatal = raw_function(&LogPythonInterface::logFatal);
525 def("B2FATAL", logFatal);
526 setattr(logFatal, "__doc__", "B2FATAL(message, *args, **kwargs)\n\n"
527 "Print a `FATAL <basf2.LogLevel.FATAL>` message. " + common_doc +
528 "\n\n.. note:: This also exits the program with an error and is "
529 "guaranteed to not return.");
530}
531
532namespace {
534 std::string pythonObjectToString(const boost::python::object& obj)
535 {
536 // boost::python::extract<std::string> triggers a false-positive
537 // -Wmaybe-uninitialized in GCC.
538#if defined(__GNUC__) && !defined(__clang__)
539#pragma GCC diagnostic push
540#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
541#endif
542 return boost::python::extract<std::string>(obj.attr("__str__")());
543#if defined(__GNUC__) && !defined(__clang__)
544#pragma GCC diagnostic pop
545#endif
546 }
547
552 auto pythonDictToMap(const dict& d)
553 {
554 std::map<std::string, std::string> result;
555 if (d.is_none()) return result;
556 const auto items = d.items();
557 const int size = len(d);
558 for (int i = 0; i < size; ++i) {
559 const auto key = pythonObjectToString(items[i][0]);
560 const auto val = pythonObjectToString(items[i][1]);
561 result.emplace(std::make_pair(key, val));
562 }
563 return result;
564 }
565
571 void dispatchMessage(LogConfig::ELogLevel logLevel, boost::python::tuple args, const boost::python::dict& kwargs)
572 {
573 int debugLevel = 0;
574 const int firstArg = logLevel == LogConfig::c_Debug ? 1 : 0;
575 const int argSize = len(args);
576 if (argSize - firstArg <= 0) {
577 PyErr_SetString(PyExc_TypeError, ("At least " + std::to_string(firstArg + 1) + " positional arguments required").c_str());
578 boost::python::throw_error_already_set();
579 }
580 if (logLevel == LogConfig::c_Debug) {
581 boost::python::extract<int> proxy(args[0]);
582 if (!proxy.check()) {
583 PyErr_SetString(PyExc_TypeError, "First argument `debugLevel` must be an integer");
584 boost::python::throw_error_already_set();
585 }
586 debugLevel = proxy;
587 }
588 if (logLevel >= LogConfig::c_Error || Belle2::LogSystem::Instance().isLevelEnabled(logLevel, debugLevel, "steering")) {
589 //Finally we know we actually will send the message: concatenate all
590 //positional arguments and convert the keyword arguments to a python dict
591 stringstream message;
592 int size = len(args);
593 for (int i = firstArg; i < size; ++i) {
594 message << pythonObjectToString(args[i]);
595 }
596 const auto cppKwArgs = pythonDictToMap(kwargs);
597 LogVariableStream lvs(message.str(), cppKwArgs);
598
599 // Now we also need to find out where the message came from: use the
600 // inspect module to get the filename/linenumbers
601 object inspect = import("inspect");
602 auto frame = inspect.attr("currentframe")();
603 // boost::python::extract<std::string> triggers a false-positive
604 // -Wmaybe-uninitialized in GCC.
605#if defined(__GNUC__) && !defined(__clang__)
606#pragma GCC diagnostic push
607#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
608#endif
609 const std::string function = extract<std::string>(frame.attr("f_code").attr("co_name"));
610 const std::string file = extract<std::string>(frame.attr("f_code").attr("co_filename"));
611#if defined(__GNUC__) && !defined(__clang__)
612#pragma GCC diagnostic pop
613#endif
614 int line = extract<int>(frame.attr("f_lineno"));
615
616 // Everything done, send it away
617 Belle2::LogSystem::Instance().sendMessage(Belle2::LogMessage(logLevel, std::move(lvs), "steering",
618 function, file, line, debugLevel));
619 }
620 }
621}
622
623boost::python::object LogPythonInterface::logDebug(boost::python::tuple args, const boost::python::dict& kwargs)
624{
625#ifndef LOG_NO_B2DEBUG
626 dispatchMessage(LogConfig::c_Debug, std::move(args), kwargs);
627#endif
628 return boost::python::object();
629}
630
631boost::python::object LogPythonInterface::logInfo(boost::python::tuple args, const boost::python::dict& kwargs)
632{
633#ifndef LOG_NO_B2INFO
634 dispatchMessage(LogConfig::c_Info, std::move(args), kwargs);
635#endif
636 return boost::python::object();
637}
638
639boost::python::object LogPythonInterface::logResult(boost::python::tuple args, const boost::python::dict& kwargs)
641#ifndef LOG_NO_B2RESULT
642 dispatchMessage(LogConfig::c_Result, std::move(args), kwargs);
643#endif
644 return boost::python::object();
645}
646
647boost::python::object LogPythonInterface::logWarning(boost::python::tuple args, const boost::python::dict& kwargs)
648{
649#ifndef LOG_NO_B2WARNING
650 dispatchMessage(LogConfig::c_Warning, std::move(args), kwargs);
651#endif
652 return boost::python::object();
653}
654
655boost::python::object LogPythonInterface::logError(boost::python::tuple args, const boost::python::dict& kwargs)
656{
657 dispatchMessage(LogConfig::c_Error, std::move(args), kwargs);
658 return boost::python::object();
659}
660
661boost::python::object LogPythonInterface::logFatal(boost::python::tuple args, const boost::python::dict& kwargs)
662{
663 dispatchMessage(LogConfig::c_Fatal, std::move(args), kwargs);
664 std::exit(1);
665 return boost::python::object();
666}
static Environment & Instance()
Static method to get a reference to the Environment instance.
The LogConfig class.
Definition LogConfig.h:22
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
ELogLevel
Definition of the supported log levels.
Definition LogConfig.h:26
@ 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
Implements a log connection to an IO Stream.
static bool getEscapeNewlinesEnabled()
Check whether we want to escape newlines on console.
static bool getPythonLoggingEnabled()
Check whether console logging via python is enabled.
static void setEscapeNewlinesEnabled(bool enabled)
Set whether we want to escape newlines on console.
static void setPythonLoggingEnabled(bool enabled)
Set whether console logging via python is enabled.
static bool terminalSupportsColors(int fileDescriptor)
Returns true if the given file descriptor is a tty and supports colors.
Implements a log connection that filters repeated messages.
Implements a log connection to stdout but with messages formatted as json objects to allow easy parsi...
Implements a log connection to a text file.
Log Connection to send the log message as JSON to a UDP server.
The LogMessage class.
Definition LogMessage.h:29
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.
static boost::python::object logFatal(boost::python::tuple args, const boost::python::dict &kwargs)
Produce fatal message.
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.
static boost::python::object logWarning(boost::python::tuple args, const boost::python::dict &kwargs)
Produce warning message.
static void exposePythonAPI()
expose python API
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 logError(boost::python::tuple args, const boost::python::dict &kwargs)
Produce error message.
static boost::python::object logResult(boost::python::tuple args, const boost::python::dict &kwargs)
Produce result message.
LogConfig::ELogLevel getLogLevel()
Get the log level.
Class for logging debug, info and error messages.
Definition LogSystem.h:46
void addPackageLogConfig(const std::string &package, const LogConfig &logConfig)
Add the per package log configuration.
Definition LogSystem.h:87
void resetMessageCounter()
Resets the message counter and error log by setting all message counts to 0.
Definition LogSystem.cc:147
LogConfig * getLogConfig()
Returns global log system configuration.
Definition LogSystem.h:78
LogConfig & getModuleLogConfig(const std::string &module)
Get the log configuration for the module with the given name.
Definition LogSystem.h:105
void enableErrorSummary(bool on)
enable/disable error/warning summary after successful execution and B2FATAL.
Definition LogSystem.h:190
bool sendMessage(LogMessage &&message)
Sends a log message using the log connection object.
Definition LogSystem.cc:66
void setMaxMessageRepetitions(unsigned repetitions)
Set maximum number of repetitions before silencing "identical" log messages.
Definition LogSystem.h:176
int getMessageCounter(LogConfig::ELogLevel logLevel) const
Returns the number of logging calls per log level.
Definition LogSystem.cc:158
static LogSystem & Instance()
Static method to get a reference to the LogSystem instance.
Definition LogSystem.cc:28
void resetLogConnections()
Removes all log connections.
Definition LogSystem.cc:41
unsigned getMaxMessageRepetitions() const
Get maximum number of repetitions before silencing "identical" log messages.
Definition LogSystem.h:169
LogConfig & getPackageLogConfig(const std::string &package)
Get the log configuration for the package with the given name.
Definition LogSystem.h:96
void addLogConnection(LogConnectionBase *logConnection)
Adds a log connection object which is used to the send the logging messages.
Definition LogSystem.cc:35
Abstract base class for different kinds of events.
STL namespace.