Nemiver  0.3
Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
nemiver::common::LogStream Class Reference

the log stream class it features logs on cout, cerr, and files. it also features log domains and log levels. More...

#include <nmv-log-stream.h>

Public Types

enum  StreamType {
  FILE_STREAM = 1, COUT_STREAM = 1 >> 1, CERR_STREAM = 1 >> 2, RFU0,
  RFU1, RFU2
}
 
enum  LogLevel { LOG_LEVEL_NORMAL =0, LOG_LEVEL_VERBOSE }
 

Public Member Functions

 LogStream (enum LogLevel a_level=LOG_LEVEL_NORMAL, const string &a_default_domain="general-domain")
 default constructor of a log stream More...
 
virtual ~LogStream ()
 destructor of the log stream class More...
 
void enable_domain (const string &a_domain, bool a_do_enable=true)
 enable or disable logging for a domain More...
 
bool is_domain_enabled (const string &a_domain)
 
LogStreamwrite (const char *a_buf, long a_buflen=-1, const string &a_domain="general-domain")
 writes a text string to the stream More...
 
LogStreamwrite (const Glib::ustring &a_msg, const string &a_domain="general-domain")
 log a message to the stream More...
 
LogStreamwrite (int a_msg, const string &a_domain="general-domain")
 
LogStreamwrite (double a_msg, const string &a_domain="general-domain")
 
LogStreamwrite (char a_msg, const string &a_domain="general-domain")
 
void push_domain (const string &a_domain)
 
void pop_domain ()
 pops the last domain that has been pushed using LogStream::push_domain. More...
 
LogStreamoperator<< (const char *a_c_string)
 log zero teriminated strings More...
 
LogStreamoperator<< (const std::string &a_string)
 log a string More...
 
LogStreamoperator<< (const Glib::ustring &a_string)
 log a UTF-8 string More...
 
LogStreamoperator<< (int an_int)
 log an integer More...
 
LogStreamoperator<< (double a_double)
 log a double More...
 
LogStreamoperator<< (char a_char)
 log a character More...
 
LogStreamoperator<< (LogStream &(*a_manipulator)(LogStream &))
 log a stream manipulator More...
 

Static Public Member Functions

static void set_stream_type (enum StreamType a_type)
 set the type of all the log streams that will be instanciated (either cout, cerr, or log file). By default, the type of stream is set to COUT_STREAM. All the logs are sent to stdout. More...
 
static enum StreamType get_stream_type ()
 gets the type of the instances of #LogStream More...
 
static void set_stream_file_path (const char *a_file_path, long a_len=-1)
 
static const char * get_stream_file_path ()
 gets the log file path, in case the stream type is set to FILE_STREAM More...
 
static void set_log_level_filter (enum LogLevel a_level)
 sets the log level filter. if the filter is set to LOG_LEVEL_NORMAL, only the log streams that have a log level set to LOG_LEVEL_NORMAL will actually log data. If the filter is set to LOG_LEVEL_VERBOSE, streams set to LOG_LEVEL_NORMAL and streams set to LOG_LEVEL_VERBOSE will be logging data. More...
 
static void set_log_domain_filter (const char *a_domain, long a_len=-1)
 sets a filter on the log domain only streams that have the same domain as the one set here will be logging data. More...
 
static void activate (bool a_activate)
 activate/de-activate the logging. More...
 
static bool is_active ()
 tests wether the logging is activated or not. More...
 
static LogStreamdefault_log_stream ()
 gets the log stream instanciated by the system by default. the options of this log stream are the global options set before the first call to this method. More...
 

Friends

LogStreamtimestamp (LogStream &)
 logs a timestamp. Basically the the current date. You use it like: nemiver::LogStream out; out << nemiver::timestamp ; More...
 
LogStreamflush (LogStream &)
 flushes the stream Use it like: nemiver::LogStream out; out << "Hello" << nemiver::flush; More...
 
LogStreamendl (LogStream &)
 log a '\n' and flushes the stream Use it like: nemiver::LogStream out; out << "hello"<< nemiver::endl; More...
 
LogStreamlevel_normal (LogStream &a_stream)
 sets the log level to normal Use it like nemiver::LogStream out; out << nemiver::level_normal << "blabla"; More...
 
LogStreamlevel_verbose (LogStream &a_stream)
 sets the log level to verbose Use it lik: nemiver::LogStream out; out << nemiver::level_verbose << "bla bla bla"; More...
 

Detailed Description

the log stream class it features logs on cout, cerr, and files. it also features log domains and log levels.

Member Enumeration Documentation

◆ LogLevel

Enumerator
LOG_LEVEL_NORMAL 
LOG_LEVEL_VERBOSE 

◆ StreamType

Enumerator
FILE_STREAM 
COUT_STREAM 
CERR_STREAM 
RFU0 
RFU1 
RFU2 

Constructor & Destructor Documentation

◆ LogStream()

nemiver::common::LogStream::LogStream ( enum LogLevel  a_level = LOG_LEVEL_NORMAL,
const string &  a_default_domain = "general-domain" 
)

default constructor of a log stream

Parameters
a_levelthe log level of the stream. This stream will log data if its log level is inferior or equal to the log level filter defined by LogStream::set_log_level_filter().
a_domainthe log domain. A stream will log data if its its log level is <= to the log level filter, and if its domain equals the domain filter.

◆ ~LogStream()

virtual nemiver::common::LogStream::~LogStream ( )
virtual

destructor of the log stream class

Member Function Documentation

◆ activate()

static void nemiver::common::LogStream::activate ( bool  a_activate)
static

activate/de-activate the logging.

Parameters
a_activatetrue to activate the logging, false to deactivate.

◆ default_log_stream()

static LogStream& nemiver::common::LogStream::default_log_stream ( )
static

gets the log stream instanciated by the system by default. the options of this log stream are the global options set before the first call to this method.

Returns
the log stream instanciated by default.

◆ enable_domain()

void nemiver::common::LogStream::enable_domain ( const string &  a_domain,
bool  a_do_enable = true 
)

enable or disable logging for a domain

Parameters
a_domainthe domain to enable logging for
a_do_enablewhen set to true, enables the logging for domain @a_domain, disable it otherwise.

◆ get_stream_file_path()

static const char* nemiver::common::LogStream::get_stream_file_path ( )
static

gets the log file path, in case the stream type is set to FILE_STREAM

Returns
the path to the log file.

◆ get_stream_type()

static enum StreamType nemiver::common::LogStream::get_stream_type ( )
static

gets the type of the instances of #LogStream

Returns
the stream type as set by LogStream::set_stream_type().

◆ is_active()

static bool nemiver::common::LogStream::is_active ( )
static

tests wether the logging is activated or not.

Returns
true if the logging is activated, false otherwise.

◆ is_domain_enabled()

bool nemiver::common::LogStream::is_domain_enabled ( const string &  a_domain)
Returns
true is logging is enabled for domain @a_domain

◆ operator<<() [1/7]

LogStream& nemiver::common::LogStream::operator<< ( char  a_char)

log a character

Parameters
a_charthe char to log

◆ operator<<() [2/7]

LogStream& nemiver::common::LogStream::operator<< ( const char *  a_c_string)

log zero teriminated strings

Parameters
a_stringthe string to log

◆ operator<<() [3/7]

LogStream& nemiver::common::LogStream::operator<< ( const Glib::ustring &  a_string)

log a UTF-8 string

Parameters
a_stringthe string to log

◆ operator<<() [4/7]

LogStream& nemiver::common::LogStream::operator<< ( const std::string &  a_string)

log a string

Parameters
a_stringthe string to log

◆ operator<<() [5/7]

LogStream& nemiver::common::LogStream::operator<< ( double  a_double)

log a double

Parameters
thedouble to log

◆ operator<<() [6/7]

LogStream& nemiver::common::LogStream::operator<< ( int  an_int)

log an integer

Parameters
an_intthe integer to log

◆ operator<<() [7/7]

LogStream& nemiver::common::LogStream::operator<< ( LogStream &(*)(LogStream &)  a_manipulator)

log a stream manipulator

Parameters
a_manipulatorthe LogStream manipulator to log

◆ pop_domain()

void nemiver::common::LogStream::pop_domain ( )

pops the last domain that has been pushed using LogStream::push_domain.

◆ push_domain()

void nemiver::common::LogStream::push_domain ( const string &  a_domain)

set the domain in against which all the coming messages will be logged. This is to be used in association with the << operators where we cannot specify the domain to log against, unlike LogStream::write() .

Parameters
a_domainthe domain to log against.

◆ set_log_domain_filter()

static void nemiver::common::LogStream::set_log_domain_filter ( const char *  a_domain,
long  a_len = -1 
)
static

sets a filter on the log domain only streams that have the same domain as the one set here will be logging data.

Parameters
a_domainthe domain name. \a_len the length of the domain name. If <0, it means that a_domain is a zero terminated string.

◆ set_log_level_filter()

static void nemiver::common::LogStream::set_log_level_filter ( enum LogLevel  a_level)
static

sets the log level filter. if the filter is set to LOG_LEVEL_NORMAL, only the log streams that have a log level set to LOG_LEVEL_NORMAL will actually log data. If the filter is set to LOG_LEVEL_VERBOSE, streams set to LOG_LEVEL_NORMAL and streams set to LOG_LEVEL_VERBOSE will be logging data.

Parameters
a_levelthe level of verbosity you want your log streams to have.

◆ set_stream_file_path()

static void nemiver::common::LogStream::set_stream_file_path ( const char *  a_file_path,
long  a_len = -1 
)
static

in the case where the stream type is set to FILE_STREAM, this methods sets the path of the file to log into. By default, the log file is ./log.txt

Parameters
a_file_paththe log file path.
a_lenthe length of the file_path. If <0, it means that a_file_path is a zero terminated string.

◆ set_stream_type()

static void nemiver::common::LogStream::set_stream_type ( enum StreamType  a_type)
static

set the type of all the log streams that will be instanciated (either cout, cerr, or log file). By default, the type of stream is set to COUT_STREAM. All the logs are sent to stdout.

Parameters
a_typethe type of the log stream

◆ write() [1/5]

LogStream& nemiver::common::LogStream::write ( char  a_msg,
const string &  a_domain = "general-domain" 
)

◆ write() [2/5]

LogStream& nemiver::common::LogStream::write ( const char *  a_buf,
long  a_buflen = -1,
const string &  a_domain = "general-domain" 
)

writes a text string to the stream

Parameters
a_bufthe buffer that contains the text string.
a_buflenthe length of the buffer. If <0, a_buf is considered as a zero terminated string.
a_domainthe domain the string has to be logged against.

◆ write() [3/5]

LogStream& nemiver::common::LogStream::write ( const Glib::ustring &  a_msg,
const string &  a_domain = "general-domain" 
)

log a message to the stream

Parameters
a_msgthe message to log
a_domainthe domain to log against

◆ write() [4/5]

LogStream& nemiver::common::LogStream::write ( double  a_msg,
const string &  a_domain = "general-domain" 
)

◆ write() [5/5]

LogStream& nemiver::common::LogStream::write ( int  a_msg,
const string &  a_domain = "general-domain" 
)

Friends And Related Function Documentation

◆ endl

LogStream& endl ( LogStream )
friend

log a '\n' and flushes the stream Use it like: nemiver::LogStream out; out << "hello"<< nemiver::endl;

◆ flush

LogStream& flush ( LogStream )
friend

flushes the stream Use it like: nemiver::LogStream out; out << "Hello" << nemiver::flush;

◆ level_normal

LogStream& level_normal ( LogStream a_stream)
friend

sets the log level to normal Use it like nemiver::LogStream out; out << nemiver::level_normal << "blabla";

◆ level_verbose

LogStream& level_verbose ( LogStream a_stream)
friend

sets the log level to verbose Use it lik: nemiver::LogStream out; out << nemiver::level_verbose << "bla bla bla";

◆ timestamp

LogStream& timestamp ( LogStream )
friend

logs a timestamp. Basically the the current date. You use it like: nemiver::LogStream out; out << nemiver::timestamp ;


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