Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to distinguish which logger called the PreRollOutCallback? #858

Open
ramezanifar opened this issue Nov 25, 2024 · 0 comments
Open

how to distinguish which logger called the PreRollOutCallback? #858

ramezanifar opened this issue Nov 25, 2024 · 0 comments

Comments

@ramezanifar
Copy link

ramezanifar commented Nov 25, 2024

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 ramezanifar changed the title how to have dedicated PreRollOutCallback callback for each logger how to have a PreRollOutCallback callback for each logger Nov 25, 2024
@ramezanifar ramezanifar changed the title how to have a PreRollOutCallback callback for each logger how to distinguish which logger called the PreRollOutCallback? Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant