Interface for logging via Python. More...
#include <logging.hh>
Public Member Functions | |
logging () | |
Default constructor. More... | |
log | debug () |
Write debug messages to Minx log. More... | |
log | info () |
Write informational messages to Minx log. More... | |
log | warning () |
Write warnings to Minx log. More... | |
log | error () |
Write errors to Minx log. More... | |
log | critical () |
Write critical errors to Minx log. More... | |
Static Public Member Functions | |
static logging | get_logger (const std::string &name) |
Create a logger object for the specified class. More... | |
Interface for logging via Python.
This class provides an API for the remaining minxlib classes to emit log messages via Python's standard logging module. This stratgey allows minxlib's log messages to be integrated with the log messages output by the rest of Minx and avoid implementing a custom logging facility within minxlib.
Additionally, leveraging Python's existing logging functionality ensures that end-users can configure Minx's logging support in a uniform way. That is, end-users don't have to be aware of the fact that minxlib is actually written in C++; to them, all of Minx is a collection of Python modules and classes whose logging support works the same.
This class does not have a Python interface. It is meant to be used only within minxlib. The following snippet of code illustrates the typical and intended usage pattern:
minxlib::logging::logging | ( | ) |
Default constructor.
This logging API is meant to be used in the following manner: each minxlib class that needs to emit log messages should define a static global logger
object in its .cc file and initialize the object in its Pythonize function by calling this class's get_logger() method. The client class can then use the logger
object to emit log messages at different levels.
The default constructor allows "empty" logger objects to be created at global scope within a .cc file. It has no other purpose. Therefore, this constructor is not (and should not be) used in any other situation.
log minxlib::logging::critical | ( | ) |
Write critical errors to Minx log.
This function returns an object that you can use to emit messages about critical errors with the stream output operator. The usage pattern is the same as described for the debug() function.
log minxlib::logging::debug | ( | ) |
Write debug messages to Minx log.
This function returns an object that you can use to emit debug messages with the stream output operator. Here is some sample code that shows how the object returned by this function is meant to be used:
In the above snippet, logger
will usually be a static global variable within the client class's .cc file and it would have been initialized in the client class's Pythonize function. The sample code in the class description shows more details.
log minxlib::logging::error | ( | ) |
Write errors to Minx log.
This function returns an object that you can use to emit errors with the stream output operator. The usage pattern is the same as described for the debug() function.
|
static |
Create a logger object for the specified class.
name | minxlib class for which we want a logger. |
This function returns a logger object that can be used by the named class to send log messages to the Minx log. It is meant to be called by the Pythonize functions of the various minxlib modules that send log messages to the Minx log. The .cc files for these modules should define a static global logger
object that is initialized by calling this function in the Pythonize function of the above-mentioned classes.
See the sample code in the class description for intended usage pattern.
log minxlib::logging::info | ( | ) |
Write informational messages to Minx log.
This function returns an object that you can use to emit informational messages with the stream output operator. The usage pattern is the same as described for the debug() function.
log minxlib::logging::warning | ( | ) |
Write warnings to Minx log.
This function returns an object that you can use to emit warnings with the stream output operator. The usage pattern is the same as described for the debug() function.