Small logger class

后端 未结 9 1472
再見小時候
再見小時候 2020-12-12 17:24

I am looking for a small lightweight logging system in c++. I have found some existing frameworks but I don\'t need all of their features at this point in time. I primarily

9条回答
  •  萌比男神i
    2020-12-12 18:15

    I strongly recommend this simple logging system: http://www.drdobbs.com/cpp/201804215. It is composed of a single header file. I have successfully used it on Linux, Windows and Mac OS X.

    You write to the log like this:

    FILE_LOG(logWARNING) << "Ops, variable x should be " << expectedX << "; is " << realX;
    

    I really like the stream syntax. It is unobtrusive, typesafe and expressive. The logging framework automatically adds a \n at the end of the line, plus date, time and indentation.

    Configuring the logs is pretty easy:

    FILELog::ReportingLevel() = logDEBUG3;
    FILE* log_fd = fopen( "mylogfile.txt", "w" );
    Output2FILE::Stream() = log_fd;
    

    This framework is also easy to extend. At work, we have recently made some adaptations to it so that it now uses an std::ofstream instead of a FILE*. As a result, we are now able to add nice features such as encrypting the logs, by chaining the streams.

提交回复
热议问题