about
11/30/2022
Logger Repo
Logger Repository
Simultaneously log messages to multiple std::ostreams
Quick Status
1.0 Concept:
2.0 Design:
-
TestLogger<Level>:
Logs string messages to one or more std::ostream instances, perhapsstd::cout and a file stream. Provides the ability to time-stamp any message, usually done only for the first message.Level determines whether a post is sent to its streams. Each logger has a level: - Level::debug
- Level::demo
- Level::results
- Level::all
Level logLevel to determine if post is sent. Applications set legLevel to determine what is posted during a program execution.logLevel = Level::all posts everything. -
QTestLogger<Level>:
Adds queued writing to the streams. A logging application simply drops a log message into the write queue and returns immediately. The intent is to minimize performance issues with logging, as that is done on a child thread while the main thread continues with its test processing.
Operation:
-
Set
logLevel = Level::all // [Level::debug, Level::demo, Level::results, Level::all] -
Create a logger with factory:
auto pDemoLogger = createLogger<Level::demo>(); -
Add streams:
pDemoLogger->addStream(&std::cout);
std::ofstream strm2;
if(openFile("test.log",strm2)
pDemoLogger->addStream(&strm2) -
Write log messages:
pDemoLogger->postDated("logging demo");
pDemoLogger->post("first msg").post("second msg"); -
End logging:
pDemoLogger->clear(); delete onpDemoLogger . That is astd::unique_ptr<ITestLogger> and will release the heap-based logger when it goes out of scope.