Exiv2::LogMsg Class Reference

Class for a log message, used by the library. Applications can set the log level and provide a customer log message handler (callback function). More...

#include <error.hpp>

Public Types

enum  Level {
  debug = 0 , info = 1 , warn = 2 , error = 3 ,
  mute = 4
}
 Defined log levels. To suppress all log messages, either set the log level to mute or set the log message handler to 0.
 
using Handler = void(*)(int, const char *)
 Type for a log message handler function. The function receives the log level and message and can process it in an application specific way. The default handler sends the log message to standard error.
 

Public Member Functions

 LogMsg (const LogMsg &)=delete
 Prevent copy-construction: not implemented.
 
LogMsgoperator= (const LogMsg &)=delete
 Prevent assignment: not implemented.
 
Creators
 LogMsg (Level msgType)
 Constructor, takes the log message type as an argument.
 
 ~LogMsg ()
 Destructor, passes the log message to the message handler depending on the log level.
 

Manipulators

std::ostringstream & os ()
 Return a reference to the ostringstream which holds the log message.
 
static void setLevel (Level level)
 Set the log level. Only log messages with a level greater or equal level are sent to the log message handler. Default log level is warn. To suppress all log messages, set the log level to mute (or set the log message handler to 0).
 
static void setHandler (Handler handler)
 Set the log message handler. The default handler writes log messages to standard error. To suppress all log messages, set the log message handler to 0 (or set the log level to mute).
 
static Level level ()
 Return the current log level.
 
static Handler handler ()
 Return the current log message handler.
 
static void defaultHandler (int level, const char *s)
 The default log handler. Sends the log message to standard error.
 

Detailed Description

Class for a log message, used by the library. Applications can set the log level and provide a customer log message handler (callback function).

This class is meant to be used as a temporary object with the related macro-magic like this:

EXV_WARNING << "Warning! Something looks fishy.\n";

which translates to

if (LogMsg::warn >= LogMsg::level() && LogMsg::handler()) LogMsg(LogMsg::warn).os() << "Warning! Something looks fishy.\n";

The macros EXV_DEBUG, EXV_INFO, EXV_WARNING and EXV_ERROR are shorthands and ensure efficient use of the logging facility: If a log message doesn't need to be generated because of the log level setting, the temp object is not even created.

Caveat: The entire log message is not processed in this case. So don't make that call any logic that always needs to be executed.


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