#include <logger.h>
Public Types | |
enum | Level { FATAL = 0, ERROR, WARN, INFO, DEBUG } |
Static Public Member Functions | |
static void | setLogFile (const std::string &logFile) |
Sets the log file. | |
static void | setTimestamp (bool flag=true) |
Add/removes the timestamp. | |
static void | setTeeMode (bool flag=true) |
Sets tee mode. | |
static void | setVerbosity (Level verbosity) |
Sets the verbosity level of the logger. | |
static void | output (const std::string &msg, Level atVerbosity) |
Logs a generic message. | |
Static Public Attributes | |
static Level | mVerbosity = Logger::INFO |
Verbosity level. |
If the log file is not set, the messages are routed to the standard output or the standard error depending on the level of the message. By default, the messages will be timestamped but the logger can be configured to not prefix the messages with a timestamp.
Limitations:
Example of use:
#include "logger.h"
int main(void) { using namespace utils;
Logger::setLogFile("/path/to/logfile");
// log messages using helper macros. LOG_DEBUG("level: " << 3) LOG_INFO("init sound") LOG_WARN("not implemented") LOG_ERROR("resource not found") LOG_FATAL("unable to init graphics")
// log messages using APIs. std::ostringstream os; os << "level: " << 3; Logger::output(os.str(), Logger::DEBUG);
Logger::output("init sound", Logger::INFO); Logger::output("not implemented", Logger::WARN); Logger::output("resource not found", Logger::ERROR); Logger::output("unable to init graphics", Logger::FATAL);
return 0; }
Definition at line 72 of file logger.h.
void utils::Logger::setLogFile | ( | const std::string & | logFile | ) | [static] |
Sets the log file.
This method will open the log file for writing, the former file contents are removed.
logFile | the log file name (may include path). |
std::ios::failure | if the log file could not be opened. |
Definition at line 83 of file logger.cpp.
static void utils::Logger::setTimestamp | ( | bool | flag = true |
) | [inline, static] |
static void utils::Logger::setTeeMode | ( | bool | flag = true |
) | [inline, static] |
static void utils::Logger::setVerbosity | ( | Level | verbosity | ) | [inline, static] |
Sets the verbosity level of the logger.
verbosity | is the level of verbosity. |
Definition at line 119 of file logger.h.
References mVerbosity.
void utils::Logger::output | ( | const std::string & | msg, | |
Level | atVerbosity | |||
) | [static] |
Logs a generic message.
msg | the message to log. | |
atVerbosity | the minimum verbosity level to log this |
std::ios::failure. |
Definition at line 106 of file logger.cpp.
References mVerbosity.
Logger::Level utils::Logger::mVerbosity = Logger::INFO [static] |
Verbosity level.
Definition at line 134 of file logger.h.
Referenced by output(), and setVerbosity().