easyloggingpp icon indicating copy to clipboard operation
easyloggingpp copied to clipboard

how to distinguish which logger called the PreRollOutCallback?

Open ramezanifar opened this issue 1 year ago • 0 comments

Is it possible to have one PreRollOutCallback callback per logger? If not, how can I distinguish which logger called it? The input arguments of the PreRollOutCallback function are file name and size. But the file name is form the conf file and can be anything.

#include "easylogging++.h"
#include <filesystem>
INITIALIZE_EASYLOGGINGPP

void rolloutHandler(const char* filename, std::size_t size) {
   // SHOULD NOT LOG ANYTHING HERE BECAUSE LOG FILE IS CLOSED!
   std::cout << "************** Rolling out [" << filename << "] because it reached [" << size << " bytes]" << std::endl;
  
  //  Here I need to distinguish between default logger and second logger. Their names can change in conf
}

int main(int, char**) {
   el::Configurations conf1("log1.conf");
   el::Loggers::reconfigureLogger("default",conf1);
   
   el::Configurations conf2("log2.conf");
   el::Loggers::reconfigureLogger("second",conf2);

   el::Loggers::addFlag(el::LoggingFlag::StrictLogFileSizeCheck);
   el::Helpers::installPreRollOutCallback(rolloutHandler);   //  Can we have callback per logger 

   for (int i = 0; i < 100; ++i){
       LOG(INFO) << "Log with default " << i;
       CLOG(INFO, "second") << "Log with second " << i;
   }
       
   el::Helpers::uninstallPreRollOutCallback();
   return 0;
}

ramezanifar avatar Nov 25 '24 05:11 ramezanifar