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

Logger type that relays to (wraps around) a PyLogger while protecting the call with GIL acquisition. More...

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

+ Inheritance diagram for tpy::GilProtectedPyLogger:
+ Collaboration diagram for tpy::GilProtectedPyLogger:

Public Member Functions

 GilProtectedPyLogger (PyLogger &logger_, bool require_gil_acquisition_=true)
 Constructor. More...
 
PyLoggergetLogger () const
 The PyLogger which we relay messages to.
 
bool getRequireGilAcquisition () const
 Whether or not we are set to acquire the GIL for emitting messages at this point.
 
void requireGilAcquisition (bool value)
 Instruct to acquire (true) or not (false) the GIL when emitting messages.
 
void emitLog (int level, const char *origin, const std::string &msg)
 The callback function for the logger, you shouldn't call this directly.
 
- Public Member Functions inherited from Tomographer::Logger::LoggerBase< GilProtectedPyLogger >
 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< GilProtectedPyLogger >
enum  
 Shortcuts to properties defined in the traits class.
 
- Static Public Member Functions inherited from Tomographer::Logger::LoggerBase< GilProtectedPyLogger >
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< GilProtectedPyLogger >
int getLevel () const
 
int getLevel () const
 
GilProtectedPyLogger * derived ()
 
const GilProtectedPyLogger * derived () const
 
void setLogLevel (int level)
 Store a new run-time log level. More...
 

Detailed Description

Logger type that relays to (wraps around) a PyLogger while protecting the call with GIL acquisition.

You should use this logger type whenever you need to provide a logger to Tomographer C++ classes which might be emitting messages while the GIL is not held.

This class behaves as a usual logger, i.e. you can call debug(), info(), warning(), etc.

Any calls to emitLog() will relay to the specified PyLogger instance after ensuring the GIL is held. GIL acquisition may be disabled by calling requireGilAcquisition(false) (or by passing false as second argument to the constructor), which may be useful in case you need to create the instance outside of a GIL-release block:

tpy::GilProtectedPyLogger gil_logger(logger, false);
// Messages emitted here should not attempt to acquire GIL as we haven't
// released it yet
tasks(..., gil_logger, ...);
{
py::gil_scoped_release gilrelease;
gil_logger->requireGilAcquisition(true);
tasks.run(); // emitted messages will acquire GIL
}
// Here we hold the GIL again
gil_logger->requireGilAcquisition(false);
// now, extract results from the tasks
py::dict results = .... extract from `tasks` ...

Definition at line 105 of file pygil.h.

Constructor & Destructor Documentation

§ GilProtectedPyLogger()

tpy::GilProtectedPyLogger::GilProtectedPyLogger ( PyLogger logger_,
bool  require_gil_acquisition_ = true 
)
inline

Constructor.

The argument logger_ is the PyLogger instance to wrap.

If require_gil_acquisition_ is False

Definition at line 115 of file pygil.h.


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