You need to create a Logger. I have coded 3 types of them:
- ConsoleLogger (classic one)
- FileLogger (do what the name suggest)
- AsyncLogger (multithreaded one)
You can actually manage multiple Loggers like one only in AsyncLogger with the AddLogger methods of it.
4 levels of logs: DEBUG, INFO, WARN, ERROR
int main()
{
/*
first param for Console and File Logger is the path/ostream
the 2nd one is the min level managed by this logger,
by default min level is 0 (DEBUG)
*/
// AsyncLogger only takes *ILogger and needs to be destroyed with delete
AsyncLogger* asyncLog = new AsyncLogger (
new ConsoleLogger(std::cerr));
asyncLog->AddLogger(new FileLogger("app.log", 1));
asyncLog->Log("Test async DEBUG", DEBUG);
asyncLog->Log("Test async WARN", WARN);
delete asyncLog;
return 0;
}
- Clone the project
- Compile with
makecommands - copy the
liblog.aandinclude/Logger.hppto your project - if you use a Makefile need to add the .hpp file to your includes
-I, the libpath with-Land the libname with-l
After trying to use s&box editor from Facepunch, and seeing a lot of Interfaces usage, i wanna learn interfaces in C++. So i asked an LLM to give me some exercises and i found some interesting ones, like this logger.