Tomographer  v5.4
Tomographer C++ Framework Documentation
tpy::PyLogger Class Reference

Logger providing transparent integration with Python's logging module. More...

#include <py/cxx/tomographerpy/pylogger.h>

+ Inheritance diagram for tpy::PyLogger:
+ Collaboration diagram for tpy::PyLogger:

Public Member Functions

 PyLogger ()
 Constructor.
 
void initPythonLogger (std::string logger_name="tomographer")
 Initialize the logger and attach it to a logger in the logging module named logger_name.
 
void setLevel (int level)
 Change the level of the current logger. Note that this will NOT automatically change the effective level of the underlying Python logger!
 
py::object toPythonLevel (int level) const
 Convert a Tomographer::Logger level to a Python logging level (Python integer)
 
py::object toPythonLevelName (int level) const
 Convert a Tomographer::Logger level to a Python logging level name (Python string)
 
int fromPythonLevel (py::object pylvl) const
 Convert a logging level to a Tomographer::Logger level constant.
 
void emitLog (int level, const char *origin, const std::string &msg)
 Callback for actually emitting log messages, don't call this manually.
 
- Public Member Functions inherited from Tomographer::Logger::LoggerBase< PyLogger >
 LoggerBase (int level_=INFO)
 Construct the base logger object. More...
 
bool enabledFor (int level_) const
 Check whether messages at the given log level are enabled. More...
 
int level () const
 Get the log level set for this logger. More...
 
void error (const char *origin, const char *fmt,...)
 emit an error message More...
 
void error (const char *origin, std::string msg)
 emit an error message More...
 
void error (const char *origin, Fn &&f)
 emit an error message More...
 
void error (Args &&...)
 Special-case implementation for messages which are known to be discarded at compile time.
 
void warning (const char *origin, const char *fmt,...)
 emit a warning message More...
 
void warning (const char *origin, std::string msg)
 emit a warning message More...
 
void warning (const char *origin, Fn &&f)
 emit a warning message More...
 
void warning (Args &&...)
 Special-case implementation for messages which are known to be discarded at compile time.
 
void info (const char *origin, const char *fmt,...)
 emit an information/notice message More...
 
void info (const char *origin, std::string msg)
 emit an information/notice message More...
 
void info (const char *origin, Fn &&f)
 emit an information/notice message More...
 
void info (Args &&...)
 Special-case implementation for messages which are known to be discarded at compile time.
 
void debug (const char *origin, const char *fmt,...)
 emit an debug message More...
 
void debug (const char *origin, std::string msg)
 emit an debug message More...
 
void debug (const char *origin, Fn &&f)
 emit an debug message More...
 
void debug (Args &&...)
 Special-case implementation for messages which are known to be discarded at compile time.
 
void longdebug (const char *origin, const char *fmt,...)
 emit a very verbose debugging message More...
 
void longdebug (const char *origin, std::string msg)
 emit a very verbose debugging message More...
 
void longdebug (const char *origin, Fn &&f)
 emit a very verbose debugging message More...
 
void longdebug (Args &&...)
 Special-case implementation for messages which are known to be discarded at compile time.
 
void log (int level, const char *origin, const char *fmt,...)
 emit a log message at the given log level. More...
 
void log (int level, const char *origin, std::string msg)
 emit a log message at the given log level. More...
 
void log (int level, const char *origin, Fn &&f)
 emit a log message at the given log level. More...
 
void log (const char *origin, const char *fmt,...)
 emit a log message at the given log level. More...
 
void log (const char *origin, const char *fmt, va_list ap)
 emit a log message at the given log level. More...
 
void log (const char *origin, std::string msg)
 emit a log message at the given log level. More...
 
void log (const char *origin, Fn f)
 emit a log message at the given log level. More...
 
void log (Args &&...)
 Special-case implementation for messages which are known to be discarded at compile time.
 

Additional Inherited Members

- Public Types inherited from Tomographer::Logger::LoggerBase< PyLogger >
enum  
 Shortcuts to properties defined in the traits class.
 
- Static Public Member Functions inherited from Tomographer::Logger::LoggerBase< PyLogger >
static bool staticallyEnabledFor (int level)
 Check whether the logger is statically disabled for some levels. More...
 
static constexpr bool staticallyEnabledFor ()
 Static version of staticallyEnabledFor() More...
 
- Protected Member Functions inherited from Tomographer::Logger::LoggerBase< PyLogger >
int getLevel () const
 
int getLevel () const
 
PyLogger * derived ()
 
const PyLogger * derived () const
 
void setLogLevel (int level)
 Store a new run-time log level. More...
 

Detailed Description

Logger providing transparent integration with Python's logging module.

This logger can be used whenever you need to specify a logger to any of Tomographer's classes, and it will log messages directly into Python's logging mechanism.

The log level is set upon initialization of the PyLogger, by replicating the effective level of the Python logging mechanism.

Note
Changes from the Python side to the logging's level will not be noticed on the C++ side. If you need to be able to dynamically change the log level, then you should expose your instance to Python (PyLogger is exposed as a class), and set the new level BOTH via Python's logging module AND by setting the logging attribute of the PyLogger instance to the same level.

Log levels correspond as follows:

(Note that there is no corresponding level name in the logging module for LONGDEBUG.)

This logger is not thread-safe. You shouldn't even use it with any Tomographer::MultiProc task dispatcher, even if these latter provide locks, because once the GIL (Global Interpreter Lock) is released, you need to acquire it before calling any Python API function. In this case, you should use a GilProtectedPyLogger.

Definition at line 92 of file pylogger.h.


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