MADARA  3.1.8
madara::logger::Logger Class Reference

A multi-threaded logger for logging to one or more destinations. More...

#include <Logger.h>

Collaboration diagram for madara::logger::Logger:

Public Member Functions

 Logger (bool log_to_stderr=true)
 Constructor. More...
 
 ~Logger ()
 Destructor. More...
 
void add_file (const std::string &filename)
 Adds a file to the logger. More...
 
void add_syslog (void)
 Adds the system log. More...
 
void add_term (void)
 Adds terminal to logger outputs. More...
 
void clear (void)
 Clears all log targets. More...
 
int get_level (void)
 Gets the maximum logging detail level. More...
 
std::string get_tag (void)
 Gets the tag used for syslogs. More...
 
void log (int level, const char *message,...)
 Logs a message to all available loggers. More...
 
void set_level (int level)
 Sets the maximum logging detail level. More...
 
void set_tag (const std::string &tag)
 Sets the tag used for syslogs (e.g. More...
 
void set_timestamp_format (const std::string &format="%x %X: ")
 Sets timestamp format. More...
 

Private Types

typedef std::vector< FILE * > FileVectors
 guard for access and changes More...
 

Private Attributes

FileVectors files_
 list of all log outputs More...
 
int level_
 the maximum detail level for logging More...
 
MADARA_LOCK_TYPE mutex_
 mutex for changes More...
 
bool syslog_added_
 tracks whether the system log has been added More...
 
std::string tag_
 the tag used for logging to system logs More...
 
bool term_added_
 tracks whether terminal output has been added More...
 
std::string timestamp_format_
 the timestamp format. Default is "" for no timestamp More...
 

Detailed Description

A multi-threaded logger for logging to one or more destinations.

A default logger is provided via madara::logger::global_logger in GlobalLogger.h

Definition at line 88 of file Logger.h.

Member Typedef Documentation

typedef std::vector<FILE *> madara::logger::Logger::FileVectors
private

guard for access and changes

vector of file handles

Definition at line 169 of file Logger.h.

Constructor & Destructor Documentation

madara::logger::Logger::Logger ( bool  log_to_stderr = true)

Constructor.

Parameters
log_to_stderrif true, log to stderr by default

Definition at line 6 of file Logger.cpp.

madara::logger::Logger::~Logger ( )

Destructor.

Definition at line 17 of file Logger.cpp.

Member Function Documentation

void madara::logger::Logger::add_file ( const std::string &  filename)
inline

Adds a file to the logger.

Parameters
filenamethe file to open and add to writing

Definition at line 14 of file Logger.inl.

void madara::logger::Logger::add_syslog ( void  )
inline

Adds the system log.

Definition at line 84 of file Logger.inl.

void madara::logger::Logger::add_term ( void  )
inline

Adds terminal to logger outputs.

Definition at line 76 of file Logger.inl.

void madara::logger::Logger::clear ( void  )
inline

Clears all log targets.

Definition at line 92 of file Logger.inl.

int madara::logger::Logger::get_level ( void  )
inline

Gets the maximum logging detail level.

Returns
the maximum level of log detail

Definition at line 68 of file Logger.inl.

std::string madara::logger::Logger::get_tag ( void  )
inline

Gets the tag used for syslogs.

Returns
the tag used for any system logging

Definition at line 52 of file Logger.inl.

void madara::logger::Logger::log ( int  level,
const char *  message,
  ... 
)

Logs a message to all available loggers.

Parameters
levelthe logging level
See also
LogLevels
Parameters
messagethe message to log

Definition at line 23 of file Logger.cpp.

void madara::logger::Logger::set_level ( int  level)
inline

Sets the maximum logging detail level.

Parameters
levelthe maximum level of log detail

Definition at line 44 of file Logger.inl.

void madara::logger::Logger::set_tag ( const std::string &  tag)
inline

Sets the tag used for syslogs (e.g.

Android Log)

Parameters
tagthe tag to use for any system logging

Definition at line 60 of file Logger.inl.

void madara::logger::Logger::set_timestamp_format ( const std::string &  format = "%x %X: ")
inline

Sets timestamp format.

Uses strftime for formatting time.

Parameters
formatthe format of the timestamp. See C++ strftime definition for common usage.

Definition at line 112 of file Logger.inl.

Member Data Documentation

FileVectors madara::logger::Logger::files_
private

list of all log outputs

Definition at line 175 of file Logger.h.

int madara::logger::Logger::level_
private

the maximum detail level for logging

Definition at line 178 of file Logger.h.

MADARA_LOCK_TYPE madara::logger::Logger::mutex_
mutableprivate

mutex for changes

Definition at line 172 of file Logger.h.

bool madara::logger::Logger::syslog_added_
private

tracks whether the system log has been added

Definition at line 184 of file Logger.h.

std::string madara::logger::Logger::tag_
private

the tag used for logging to system logs

Definition at line 187 of file Logger.h.

bool madara::logger::Logger::term_added_
private

tracks whether terminal output has been added

Definition at line 181 of file Logger.h.

std::string madara::logger::Logger::timestamp_format_
private

the timestamp format. Default is "" for no timestamp

Definition at line 190 of file Logger.h.


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