-
Notifications
You must be signed in to change notification settings - Fork 0
Logger
The framework allows you to define several loggers which will write logs in the format hh:mm:ss:µµµµµµ -- [logger name] -- message
.
You can decide to make the Logger write to a file or to the terminal.
There are 5 levels of logging. In ascending order:
- DEBUG
- INFO
- WARNING
- ERROR
- CRITICAL
DEBUG to WARNING logs are printed on the standard output (except if the Logger logs to a file). ERROR and CRITICAL logs are printed on the error output.
To create a Logger, you must always use the LoggerManager:
// create a Logger named "foo" which prints any log with level DEBUG and above.
fwk::Logger& foo = fwk::LoggerManager::get().init("foo", fwk::Logger::Level::DEBUG);
// create a Logger named "bar" which prints any ERROR and CRITICAL log into a file.
fwk::Logger& bar = fwk::LoggerManager::get().init("bar", fwk::Logger::Level::ERROR, "/home/foobar/logs/logs.txt");
Once created, you can get your Logger anywhere using:
fwk::Logger& foo = fwk::LoggerManager::get().getLogger("foo");
This isn't mandatory, since any logger will be destroyed with the framework, but you can remove a Logger using:
fwk::LoggerManager::get().endLogger("foo");
fwk::Logger& foo = fwk::LoggerManager::get().init("foo", fwk::Logger::Level::INFO);
// nothing is written, as DEBUG < INFO
foo.log("debug message", fwk::Logger::Level::DEBUG);
// message written:
// 15:28:32:468413 -- foo -- info message
foo.log("info message", fwk::Logger::Level::INFO);
You can ignore any message from one of your logger by initializing it with the level fwk::Logger::Level::IGNORE
. Any log, even with this level, will be ignored.
The logger with the name "cppframework" is already used. As long as you don't initialize it, any log from the framework will be ignored.