abumq / easyloggingpp

C++ logging library. It is extremely powerful, extendable, light-weight, fast performing, thread and type safe and consists of many built-in features. It provides ability to write logs in your own customized format. It also provide support for logging your classes, third-party libraries, STL and third-party containers etc.
MIT License
3.75k stars 918 forks source link

performance logging TIMED_SCOPE(timerBlkObj) to a file #839

Open yalov opened 1 year ago

yalov commented 1 year ago

could someone provide example how to put all performance logging into a file a1.txt?

looks like this example is doing something different and more complicated: https://github.com/abumq/easyloggingpp/blob/master/samples/STL/custom-performance-output.cpp I have not understood how to use that.

This code output performance to console, how to make it output to second logger (--a1) ?

easylogging++.conf

-- default
    * GLOBAL:
        FORMAT               =  "%datetime{%Y-%M-%d %H:%m:%s.%g}      %level: %msg"
        FILENAME             =  "log.txt"
        ENABLED              =  true
        TO_FILE              =  true
        TO_STANDARD_OUTPUT   =  true
        SUBSECOND_PRECISION  =  3
        PERFORMANCE_TRACKING =  true
        MAX_LOG_FILE_SIZE    =  268435456 ## 256MB
        LOG_FLUSH_THRESHOLD  =  100 

--a1
    * GLOBAL:
        FORMAT               =  "%msg"
        FILENAME             =  "a1.txt"
        TO_STANDARD_OUTPUT   =  true
        PERFORMANCE_TRACKING =  true

main.cpp

#include "easylogging++.h"
#include <chrono>
#include <thread>
using namespace std::chrono_literals;

INITIALIZE_EASYLOGGINGPP

int main() {
    el::Loggers::addFlag(el::LoggingFlag::MultiLoggerSupport);
    el::Loggers::configureFromGlobal("./easylogging++.conf");

    for (int i = 0; i <= 50; ++i) {
        TIMED_SCOPE(timerBlkObj, "a1"); // this need to go to a1.txt and to console
        std::this_thread::sleep_for(10ms);
    }

    return 0;
}