Geogram  Version 1.9.1-rc
A programming library of geometric algorithms
GEO::Logger Class Reference

Generic logging framework. More...

#include <geogram/basic/logger.h>

Inheritance diagram for GEO::Logger:
GEO::Environment GEO::Counted

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 Environmentfind_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 Loggerinstance ()
 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 Environmentinstance ()
 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
 

Detailed Description

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()).

Definition at line 358 of file logger.h.

Constructor & Destructor Documentation

◆ Logger()

GEO::Logger::Logger ( )
protected

Logger default constructor.

The constructor is never called directly but through a call to initialize().

Member Function Documentation

◆ div()

static std::ostream& GEO::Logger::div ( const std::string &  title)
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:

Logger::div("new section") << "message" << endl ;
static std::ostream & div(const std::string &title)
Creates a division in the log output.
Parameters
[in]titletitle of the division

◆ div_stream()

std::ostream& GEO::Logger::div_stream ( const std::string &  title)
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:

Logger::div("new section") << "message" << endl ;
Parameters
[in]titletitle of the division

◆ err()

static std::ostream& GEO::Logger::err ( const std::string &  feature)
static

Gets the stream to send error messages.

Example:

Logger::err("feature_name") << "problem with args" << endl ;
static std::ostream & err(const std::string &feature)
Gets the stream to send error messages.
Parameters
[in]featurename of the feature associated to the incoming warning messages
Returns
a reference to the warning stream

◆ err_console()

std::ostream& GEO::Logger::err_console ( )
protected

Gets an output stream that sends messages to the standard error.

This one is returned by out(), err(), warn(), status() whenever multiple threads are running. It serializes writes line by line, so that messages from different threads are not mixed.

◆ err_stream()

std::ostream& GEO::Logger::err_stream ( const std::string &  feature)
protected

Gets the stream to send error messages.

Example:

Logger::err("feature_name") << "problem with args" << endl ;
Parameters
[in]featurename of the feature associated to the incoming warning messages
Returns
a reference to the warning stream

◆ get_local_value()

bool GEO::Logger::get_local_value ( const std::string &  name,
std::string &  value 
) const
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).

Parameters
[in]namename of the property
[out]valuereceives the value of the property
Return values
trueif the property is a valid Logger property
falseotherwise
See also
Environment::get_value()

Implements GEO::Environment.

◆ initialize()

static void GEO::Logger::initialize ( )
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().

See also
instance()

◆ instance()

static Logger* GEO::Logger::instance ( )
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.

Returns
A pointer to the Logger if initialized, null otherwise
See also
initialize()
terminate()

◆ is_client()

bool GEO::Logger::is_client ( LoggerClient client) const

Checks if a client is registered.

Parameters
[in]clienta logger client
Return values
trueif client is registered to the Logger
falseotherwise

◆ is_initialized()

static bool GEO::Logger::is_initialized ( )
static

Tests whether the Logger is initialized.

Certain error-reporting functions may be triggered before the Logger is initialized or after it is terminated. This function is meant to help them determine whether the logger can be used.

Return values
trueif the Logger can be used
falseotherwise

◆ is_minimal()

bool GEO::Logger::is_minimal ( ) const
inline

Checks the minimal mode.

Return values
trueif the minimal mode is on
falseotherwise

Definition at line 535 of file logger.h.

◆ is_pretty()

bool GEO::Logger::is_pretty ( ) const
inline

Checks the console pretty mode.

Return values
trueif the console pretty mode is on
falseotherwise

Definition at line 556 of file logger.h.

◆ is_quiet()

bool GEO::Logger::is_quiet ( ) const
inline

Checks the quiet mode.

Return values
trueif the quiet mode is on
falseotherwise

Definition at line 513 of file logger.h.

◆ notify()

void GEO::Logger::notify ( LoggerStream sender,
const std::string &  message 
)
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

Parameters
[in]senderthe LoggerStream that sent the message
[in]messagethe text of the message
See also
LoggerStream()
notify_out()
notify_warn()
notify_err()
notify_status()

◆ notify_err()

void GEO::Logger::notify_err ( const std::string &  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.

Parameters
[in]messagetext of the message
See also
LoggerClient::err()

◆ notify_out()

void GEO::Logger::notify_out ( const std::string &  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.

Parameters
[in]messagetext of the message
See also
LoggerClient::out()

◆ notify_status()

void GEO::Logger::notify_status ( const std::string &  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.

Parameters
[in]messagetext of the message
See also
LoggerClient::status()

◆ notify_warn()

void GEO::Logger::notify_warn ( const std::string &  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.

Parameters
[in]messagetext of the message
See also
LoggerClient::warn()

◆ out()

static std::ostream& GEO::Logger::out ( const std::string &  feature)
static

Gets the stream to send information messages.

Example:

Logger::out("feature_name") << "initialized" << endl ;
static std::ostream & out(const std::string &feature)
Gets the stream to send information messages.
Parameters
[in]featurename of the feature associated to the incoming information messages
Returns
a reference to the information stream

◆ out_stream()

std::ostream& GEO::Logger::out_stream ( const std::string &  feature)
protected

Gets the stream to send information messages.

Example:

Logger::out("feature_name") << "initialized" << endl ;
Parameters
[in]featurename of the feature associated to the incoming information messages
Returns
a reference to the information stream

◆ register_client()

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().

Parameters
[in]clienta logger client
See also
unregister_client()

◆ set_local_value()

bool GEO::Logger::set_local_value ( const std::string &  name,
const std::string &  value 
)
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.

Parameters
[in]namename of the property
[in]valuevalue of the property
Return values
trueif the property was successfully set
falseotherwise
See also
Environment::set_value()

Implements GEO::Environment.

◆ set_minimal()

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().

Parameters
[in]flagset to true/false to turn the minimal mode on/off
Note
The minimal mode is off by default
See also
set_value()

◆ set_pretty()

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().

Parameters
[in]flagset to true/false to turn the quiet mode on/off

◆ set_quiet()

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().

Parameters
[in]flagset to true/false to turn the quiet mode on/off
Note
The quiet mode is on by default
See also
set_value()

◆ status()

static std::ostream& GEO::Logger::status ( )
static

Gets the stream to send status messages.

Example:

Logger::status() << "Hyperdrive activated" << endl ;
static std::ostream & status()
Gets the stream to send status messages.
Returns
a reference to the status stream

◆ status_stream()

std::ostream& GEO::Logger::status_stream ( )
protected

Gets the stream to send status messages.

Example:

Logger::status() << "Hyperdrive activated" << endl ;
Returns
a reference to the status stream

◆ terminate()

static void GEO::Logger::terminate ( )
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()

See also
instance()

◆ unregister_client()

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.

Parameters
[in]clienta logger client
See also
register_client()

◆ warn()

static std::ostream& GEO::Logger::warn ( const std::string &  feature)
static

Gets the stream to send warning messages.

Example:

Logger::warn("feature_name") << "strange value" << endl ;
static std::ostream & warn(const std::string &feature)
Gets the stream to send warning messages.
Parameters
[in]featurename of the feature associated to the incoming error messages
Returns
a reference to the error stream

◆ warn_stream()

std::ostream& GEO::Logger::warn_stream ( const std::string &  feature)
protected

Gets the stream to send warning messages.

Example:

Logger::warn("feature_name") << "strange value" << endl ;
Parameters
[in]featurename of the feature associated to the incoming error messages
Returns
a reference to the error stream

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