#include <logger.h>
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 75 of file logger.h.
Public Types | |
| enum | Level { FATAL = 0, ERROR, WARN, INFO, DEBUG } |
Static Public Member Functions | |
| void | setLogFile (std::string const &logFile) |
| Sets the log file. | |
| void | setTimestamp (bool flag=true) |
| Add/removes the timestamp. | |
| void | setTeeMode (bool flag=true) |
| Sets tee mode. | |
| void | setVerbosity (Level verbosity) |
| Sets the verbosity level of the logger. | |
| void | output (std::string const &msg, Level atVerbosity) |
| Logs a generic message. | |
Static Public Attributes | |
| Level | mVerbosity = Logger::INFO |
| Verbosity level. | |
Static Private Member Functions | |
| void | output (std::ostream &os, std::string const &msg, char const *prefix) |
| Logs a generic message. | |
Static Private Attributes | |
| bool | mHasTimestamp = true |
| Timestamp flag. | |
| bool | mTeeMode = false |
| Tee mode flag. | |
|
|
|
|
||||||||||||||||
|
Logs a generic message.
Definition at line 70 of file logger.cpp. |
|
||||||||||||
|
Logs a generic message.
Definition at line 108 of file logger.cpp. |
|
|
Sets the log file. This method will open the log file for writing, the former file contents are removed.
Definition at line 85 of file logger.cpp. |
|
|
Sets tee mode.
|
|
|
Add/removes the timestamp.
|
|
|
Sets the verbosity level of the logger.
|
|
|
Timestamp flag.
Definition at line 38 of file logger.cpp. |
|
|
Tee mode flag.
Definition at line 39 of file logger.cpp. |
|
|
Verbosity level.
Definition at line 40 of file logger.cpp. |
1.3.9.1