Belle II Software  release-05-02-19
LogPythonInterface.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010-2018 Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Martin Ritter, Thomas Kuhr, Thomas Hauth *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #pragma once
12 
13 #include <framework/logging/LogConfig.h>
14 
15 #include <boost/python/dict.hpp>
16 
17 #include <string>
18 
19 namespace Belle2 {
46  class LogPythonInterface {
47  public:
49  LogPythonInterface() {};
50 
57 
64 
70  void setDebugLevel(int level);
71 
78  void setLogInfo(LogConfig::ELogLevel level, int info);
79 
86  void setPackageLogConfig(const std::string& package, const LogConfig& config);
87 
93  void setMaxMessageRepetitions(unsigned repetitions);
94 
101 
108 
114  int getDebugLevel();
115 
122  int getLogInfo(LogConfig::ELogLevel level);
123 
130  LogConfig& getPackageLogConfig(const std::string& package);
131 
137  unsigned getMaxMessageRepetitions() const;
138 
145  void addLogFile(const std::string& filename, bool append = false);
146 
150  void addLogConsole();
151 
158  void addLogJSON(bool complete);
159 
160 
166  void addLogUDP(const std::string& hostname, unsigned short port);
167 
173  void addLogConsole(bool color);
174 
178  void reset();
179 
183  void zeroCounters();
184 
186  void enableErrorSummary(bool on);
187 
191  void setPythonLoggingEnabled(bool enabled) const;
192 
196  bool getPythonLoggingEnabled() const;
197 
201  void setEscapeNewlinesEnabled(bool enabled) const;
202 
206  bool getEscapeNewlinesEnabled() const;
207 
214  static boost::python::object logDebug(boost::python::tuple args, const boost::python::dict& kwargs);
221  static boost::python::object logInfo(boost::python::tuple args, const boost::python::dict& kwargs);
222 
229  static boost::python::object logResult(boost::python::tuple args, const boost::python::dict& kwargs);
236  static boost::python::object logWarning(boost::python::tuple args, const boost::python::dict& kwargs);
243  static boost::python::object logError(boost::python::tuple args, const boost::python::dict& kwargs);
244 
251  static boost::python::object logFatal(boost::python::tuple args, const boost::python::dict& kwargs);
252 
254  boost::python::dict getLogStatistics();
256  static void exposePythonAPI();
257  protected:
258  };
259 
261 } // end namespace Belle2
Belle2::LogPythonInterface::getLogInfo
int getLogInfo(LogConfig::ELogLevel level)
Get the printed log information for the given level.
Definition: LogPythonInterface.cc:83
Belle2::LogPythonInterface::logError
static boost::python::object logError(boost::python::tuple args, const boost::python::dict &kwargs)
Produce error message.
Definition: LogPythonInterface.cc:611
Belle2::LogPythonInterface::getPythonLoggingEnabled
bool getPythonLoggingEnabled() const
Get flag if logging should be done via python sys.stdout
Definition: LogPythonInterface.cc:143
Belle2::LogPythonInterface::logDebug
static boost::python::object logDebug(boost::python::tuple args, const boost::python::dict &kwargs)
Produce debug message.
Definition: LogPythonInterface.cc:579
Belle2::LogPythonInterface::getAbortLevel
LogConfig::ELogLevel getAbortLevel()
Get the abort level.
Definition: LogPythonInterface.cc:73
Belle2::LogPythonInterface::addLogConsole
void addLogConsole()
Add the console as output connection.
Definition: LogPythonInterface.cc:113
Belle2::LogPythonInterface::addLogFile
void addLogFile(const std::string &filename, bool append=false)
Add a file as output connection.
Definition: LogPythonInterface.cc:108
Belle2::LogPythonInterface::LogPythonInterface
LogPythonInterface()
ctor
Definition: LogPythonInterface.h:57
Belle2::LogPythonInterface::setMaxMessageRepetitions
void setMaxMessageRepetitions(unsigned repetitions)
Set maximum number of repetitions before silencing "identical" log messages.
Definition: LogPythonInterface.cc:63
Belle2::LogPythonInterface::getLogStatistics
boost::python::dict getLogStatistics()
return dict with log statistics
Definition: LogPythonInterface.cc:159
Belle2::LogPythonInterface::addLogUDP
void addLogUDP(const std::string &hostname, unsigned short port)
Add a UDP server as an output connection.
Definition: LogPythonInterface.cc:103
Belle2::LogPythonInterface::logFatal
static boost::python::object logFatal(boost::python::tuple args, const boost::python::dict &kwargs)
Produce fatal message.
Definition: LogPythonInterface.cc:617
Belle2::LogPythonInterface::getMaxMessageRepetitions
unsigned getMaxMessageRepetitions() const
Get maximum number of repetitions before silencing "identical" log messages.
Definition: LogPythonInterface.cc:93
Belle2::LogConfig::ELogLevel
ELogLevel
Definition of the supported log levels.
Definition: LogConfig.h:36
Belle2::LogPythonInterface::setAbortLevel
void setAbortLevel(LogConfig::ELogLevel level)
Set the abort log level.
Definition: LogPythonInterface.cc:43
Belle2::LogPythonInterface::reset
void reset()
Reset logging connections.
Definition: LogPythonInterface.cc:123
Belle2::LogPythonInterface::getPackageLogConfig
LogConfig & getPackageLogConfig(const std::string &package)
Get the LogConfig for the given package.
Definition: LogPythonInterface.cc:88
Belle2::LogPythonInterface::zeroCounters
void zeroCounters()
Reset logging counters.
Definition: LogPythonInterface.cc:128
Belle2::LogPythonInterface::getLogLevel
LogConfig::ELogLevel getLogLevel()
Get the log level.
Definition: LogPythonInterface.cc:68
Belle2::LogPythonInterface::exposePythonAPI
static void exposePythonAPI()
expose python API
Definition: LogPythonInterface.cc:190
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::LogPythonInterface::setDebugLevel
void setDebugLevel(int level)
Set the debug messaging level.
Definition: LogPythonInterface.cc:48
Belle2::LogPythonInterface::setPackageLogConfig
void setPackageLogConfig(const std::string &package, const LogConfig &config)
Set LogConfig for a given package.
Definition: LogPythonInterface.cc:58
Belle2::LogPythonInterface::logInfo
static boost::python::object logInfo(boost::python::tuple args, const boost::python::dict &kwargs)
Produce info message.
Definition: LogPythonInterface.cc:587
Belle2::LogPythonInterface::setLogInfo
void setLogInfo(LogConfig::ELogLevel level, int info)
Set the printed log information for the given level.
Definition: LogPythonInterface.cc:53
Belle2::LogPythonInterface::enableErrorSummary
void enableErrorSummary(bool on)
Enable/Disable error summary.
Definition: LogPythonInterface.cc:133
Belle2::LogPythonInterface::logResult
static boost::python::object logResult(boost::python::tuple args, const boost::python::dict &kwargs)
Produce result message.
Definition: LogPythonInterface.cc:595
Belle2::LogPythonInterface::addLogJSON
void addLogJSON(bool complete)
Add the console as output connection but print the log messages as json objects so that they can be p...
Definition: LogPythonInterface.cc:98
Belle2::LogPythonInterface::getEscapeNewlinesEnabled
bool getEscapeNewlinesEnabled() const
Get flag if newlines in log messages to console should be replaced by ' '`.
Definition: LogPythonInterface.cc:153
Belle2::LogPythonInterface::getDebugLevel
int getDebugLevel()
Get the debug level.
Definition: LogPythonInterface.cc:78
Belle2::LogConfig
The LogConfig class.
Definition: LogConfig.h:32
Belle2::LogPythonInterface::setLogLevel
void setLogLevel(LogConfig::ELogLevel level)
Set the log level.
Definition: LogPythonInterface.cc:34
Belle2::LogPythonInterface::setPythonLoggingEnabled
void setPythonLoggingEnabled(bool enabled) const
Set flag if logging should be done via python sys.stdout
Definition: LogPythonInterface.cc:138
Belle2::LogPythonInterface::setEscapeNewlinesEnabled
void setEscapeNewlinesEnabled(bool enabled) const
Set flag if newlines in log messages to console should be replaced by ' '.
Definition: LogPythonInterface.cc:148
Belle2::LogPythonInterface::logWarning
static boost::python::object logWarning(boost::python::tuple args, const boost::python::dict &kwargs)
Produce warning message.
Definition: LogPythonInterface.cc:603