Geogram
Version 1.9.1-rc
A programming library of geometric algorithms
|
Generic logging framework. More...
#include <geogram/basic/logger.h>
Public Member Functions | |
void | register_client (LoggerClient *client) |
Adds a client to the Logger. More... | |
void | unregister_client (LoggerClient *client) |
Removes a client from the Logger. More... | |
void | unregister_all_clients () |
Unregisters all the registered clients. | |
bool | is_client (LoggerClient *client) const |
Checks if a client is registered. More... | |
void | set_quiet (bool flag) |
Sets the quiet mode. More... | |
bool | is_quiet () const |
Checks the quiet mode. More... | |
void | set_minimal (bool flag) |
Sets the minimal mode. More... | |
bool | is_minimal () const |
Checks the minimal mode. More... | |
void | set_pretty (bool flag) |
Sets the console pretty mode. More... | |
bool | is_pretty () const |
Checks the console pretty mode. More... | |
Public Member Functions inherited from GEO::Environment | |
virtual bool | add_environment (Environment *env) |
Adds a child environment. More... | |
bool | has_value (const std::string &name) const |
Tests if a variable exists. More... | |
virtual bool | get_value (const std::string &name, std::string &value) const |
Retrieves the value of a variable. More... | |
std::string | get_value (const std::string &name) const |
Retrieves the value of a variable. More... | |
virtual bool | set_value (const std::string &name, const std::string &value) |
Sets a variable value. More... | |
virtual Environment * | find_environment (const std::string &name) |
Finds the environment that declares a variable as a local name. More... | |
virtual bool | add_observer (const std::string &name, VariableObserver *observer) |
Attaches an observer to a variable. More... | |
virtual bool | remove_observer (const std::string &name, VariableObserver *observer) |
Detaches an observer from a variable. More... | |
virtual bool | notify_observers (const std::string &name, bool recursive=false) |
Notifies observers. More... | |
Public Member Functions inherited from GEO::Counted | |
void | ref () const |
Increments the reference count. More... | |
void | unref () const |
Decrements the reference count. More... | |
bool | is_shared () const |
Check if the object is shared. More... | |
int | nb_refs () const |
Gets the number of references that point to this object. More... | |
Static Public Member Functions | |
static void | initialize () |
Initializes the logging system. More... | |
static void | terminate () |
Terminates the logging system. More... | |
static Logger * | instance () |
Returns the Logger single instance. More... | |
static bool | is_initialized () |
Tests whether the Logger is initialized. More... | |
static std::ostream & | div (const std::string &title) |
Creates a division in the log output. More... | |
static std::ostream & | out (const std::string &feature) |
Gets the stream to send information messages. More... | |
static std::ostream & | err (const std::string &feature) |
Gets the stream to send error messages. More... | |
static std::ostream & | warn (const std::string &feature) |
Gets the stream to send warning messages. More... | |
static std::ostream & | status () |
Gets the stream to send status messages. More... | |
Static Public Member Functions inherited from GEO::Environment | |
static Environment * | instance () |
Gets the root environment. More... | |
static void | terminate () |
Cleans up the environment. More... | |
Static Public Member Functions inherited from GEO::Counted | |
static void | ref (const Counted *counted) |
Increments the reference count. More... | |
static void | unref (const Counted *counted) |
Decrements the reference count. More... | |
Protected Member Functions | |
Logger () | |
Logger default constructor. More... | |
~Logger () override | |
Logger destructor. | |
std::ostream & | div_stream (const std::string &title) |
Creates a division in the log output. More... | |
std::ostream & | out_stream (const std::string &feature) |
Gets the stream to send information messages. More... | |
std::ostream & | err_stream (const std::string &feature) |
Gets the stream to send error messages. More... | |
std::ostream & | warn_stream (const std::string &feature) |
Gets the stream to send warning messages. More... | |
std::ostream & | status_stream () |
Gets the stream to send status messages. More... | |
std::ostream & | err_console () |
Gets an output stream that sends messages to the standard error. More... | |
void | notify (LoggerStream *sender, const std::string &message) |
Receives a message from a logger stream. More... | |
void | notify_out (const std::string &message) |
Handles an information message. More... | |
void | notify_warn (const std::string &message) |
Handles a warning message. More... | |
void | notify_err (const std::string &message) |
Handles an error message. More... | |
void | notify_status (const std::string &message) |
Handles a status message. More... | |
bool | set_local_value (const std::string &name, const std::string &value) override |
Sets a Logger property. More... | |
bool | get_local_value (const std::string &name, std::string &value) const override |
Gets a Logger property. More... | |
Protected Member Functions inherited from GEO::Environment | |
~Environment () override | |
Environment destructor. More... | |
bool | notify_observers (const std::string &name, const std::string &value, bool recursive) |
Notifies observers. More... | |
bool | notify_local_observers (const std::string &name, const std::string &value) |
Notifies local observers. More... | |
Protected Member Functions inherited from GEO::Counted | |
Counted () | |
Creates a reference counted object. More... | |
virtual | ~Counted () |
Destroys a reference counted object. More... | |
Friends | |
class | LoggerStream |
class | LoggerStreamBuf |
Generic logging framework.
The Logger is a framework for logging messages with different severities to various destinations.
Logging destinations can be specified by registering LoggerClients to the Logger (see register_client()). Predefined clients exist to log messages to a file or to the console with a pretty or standard formatting (see set_pretty()). Any number of clients can be registered to the Logger.
The Logger provides 4 level of severities, each of them having its own LoggerStream:
Thus logging a message to the specific stream is equivalent of sending a message of the correspnding severity. For instance, logging a message to the warn() stream means sending a warning message to the Logger.
The Logger also provides a pseudo stream div() that creates a division in the log output, that is the log can be structured in kind of chapters introduced by a heading title.
Messages are associated to features. A feature can be considered as the source context (eg: messages sent to the Logger by the mesh I/O module specify feature "I/O"). The feature is specified when selecting the stream to. When a message is sent to the LoggerClients by the Logger, it contains information about its severity and the associated feature.
Features are not only information about of the message source, they also support a message filtering mechanism. Specific features can be enabled by setting the Logger property log:features to a colon-separated list of enabled feature names, or disabled by setting the Logger property log:features_exclude to a colon-separated list of excluded feature names (see set_value()). Note that setting property log:features to the special value "*" globally enables all logging features (this is the default).
The Logger can also be turned off temporarily by setting the quiet mode to true
, which disables all messages, warnings and errors included (set set_quiet()).
|
protected |
Logger default constructor.
The constructor is never called directly but through a call to initialize().
|
static |
Creates a division in the log output.
This is used to start a new "block" of output log with title title
. LoggerClients are free to honor div messages or to implement them the way they prefer. Example:
[in] | title | title of the division |
|
protected |
Creates a division in the log output.
This is used to start a new "block" of output log with title title
. LoggerClients are free to honor div messages or to implement them the way they prefer. Example:
[in] | title | title of the division |
|
static |
Gets the stream to send error messages.
Example:
[in] | feature | name of the feature associated to the incoming warning messages |
|
protected |
|
protected |
Gets the stream to send error messages.
Example:
[in] | feature | name of the feature associated to the incoming warning messages |
|
overrideprotectedvirtual |
Gets a Logger property.
Retrieves the value of the property name
and stores it in value
. The property must be a valid Logger property (see log:xxx properties in Vorpaline's help).
[in] | name | name of the property |
[out] | value | receives the value of the property |
true | if the property is a valid Logger property |
false | otherwise |
Implements GEO::Environment.
|
static |
Initializes the logging system.
This function must be called once at program startup to create and initialize the Logger instance. It is called by GEO::initialize().
|
static |
Returns the Logger single instance.
This function does not create the Logger instance. Calling instance() before initialize() has been called returns a null
pointer. Similarly, calling instance() after terminate() has been called returns a null
pointer.
bool GEO::Logger::is_client | ( | LoggerClient * | client | ) | const |
Checks if a client is registered.
[in] | client | a logger client |
true | if client is registered to the Logger |
false | otherwise |
|
static |
|
inline |
|
inline |
|
inline |
|
protected |
Receives a message from a logger stream.
This function is called by the LoggerStream stream
when a new sequence of characters message
is sent to the stream. The function dispatches the message to appropriate handling functions notify_xxx() according to the type of the stream
[in] | sender | the LoggerStream that sent the message |
[in] | message | the text of the message |
|
protected |
Handles an error message.
This formats the error message and sends it to the registered clients by calling their function err(). Error messages ignore feature filters or exclusion rules and are always sent to the clients.
[in] | message | text of the message |
|
protected |
Handles an information message.
This formats the information message and sends it to the registered clients by calling their function out(). Information messages are sent to the clients only if the current Logger feature matches the current filter or does not matches any feature exclusion rule. sent to the clients.
[in] | message | text of the message |
|
protected |
Handles a status message.
This formats the status message and sends it to the registered clients by calling their function status(). Status messages ignore feature filters or exclusion rules and are always sent to the clients.
[in] | message | text of the message |
|
protected |
Handles a warning message.
This formats the warning message and sends it to the registered clients by calling their function warn(). Warning messages ignore feature filters or exclusion rules and are always sent to the clients.
[in] | message | text of the message |
|
static |
Gets the stream to send information messages.
Example:
[in] | feature | name of the feature associated to the incoming information messages |
|
protected |
Gets the stream to send information messages.
Example:
[in] | feature | name of the feature associated to the incoming information messages |
void GEO::Logger::register_client | ( | LoggerClient * | client | ) |
Adds a client to the Logger.
This adds client client
to the existing clients and starts sending messages to it. The Logger takes ownership on the client
, so there's no need to delete it, unless the client is unregistered by unregister_client().
[in] | client | a logger client |
|
overrideprotectedvirtual |
Sets a Logger property.
Sets the property name
with value value
in the Logger. The property must be a valid Logger property (see log:xxx properties in Vorpaline's help) and value
must be a legal value for the property.
[in] | name | name of the property |
[in] | value | value of the property |
true | if the property was successfully set |
false | otherwise |
Implements GEO::Environment.
void GEO::Logger::set_minimal | ( | bool | flag | ) |
Sets the minimal mode.
When the Logger is in minimal mode, only warning and error messages sent to it are dispatched to the registered clients. The minimal mode can also be set by setting the value of the property "log:minimal" with set_value().
[in] | flag | set to true/false to turn the minimal mode on/off |
void GEO::Logger::set_pretty | ( | bool | flag | ) |
Sets the console pretty mode.
When the Logger console is in pretty mode, messages are formatted in a fancy way using nice boxes with titles, and long messages are smartly wrapped and aligned on the message features. Otherwise, the messages are displayed "as is". The console pretty mode can also be set by setting the value of the property "log:pretty" with set_value().
[in] | flag | set to true/false to turn the quiet mode on/off |
void GEO::Logger::set_quiet | ( | bool | flag | ) |
Sets the quiet mode.
When the Logger is in quiet mode, all messages sent to it are ignored and not dispatched to the registered clients. The quiet mode can also be set by setting the value of the property "log:quiet" with set_value().
[in] | flag | set to true/false to turn the quiet mode on/off |
|
static |
Gets the stream to send status messages.
Example:
|
protected |
Gets the stream to send status messages.
Example:
|
static |
Terminates the logging system.
This function must be called once when the program ends to delete the Logger instance. It is called by GEO::terminate()
void GEO::Logger::unregister_client | ( | LoggerClient * | client | ) |
Removes a client from the Logger.
This removes client client
from the list of registered clients if present. After being removed, the client will no longer receive messages from the Logger. It is also the responsibility of the client code to delete the client appropriately.
[in] | client | a logger client |
|
static |
Gets the stream to send warning messages.
Example:
[in] | feature | name of the feature associated to the incoming error messages |
|
protected |
Gets the stream to send warning messages.
Example:
[in] | feature | name of the feature associated to the incoming error messages |