Easylogging++ how to configure with single macro?

2.5k views Asked by At

I would like to create a simple macro that does what _INITIALIZE_EASYLOGGINGPP does, but that accepts a configuration string like this one:

"*GLOBAL:\nFILENAME = my_app.log\nFORMAT = %datetime{%Y.%M.%d-%H.%m.%s.%g}, %level, %msg\n*INFO:\n ENABLED=false"

The macro would then replace:

_INITIALIZE_EASYLOGGINGPP

by

INITIALIZE_ELPP_WITH_CONFIG("myconfigstring")

Anyone has an idea how to do that?

1

There are 1 answers

2
Antoine Lamaison On

You should create a function like this one :

void initializeLogs(const char* config_string)
{
    _INITIALIZE_EASYLOGGINGPP
   easyloggingpp::Configurations c;
   c.setToDefault();
   c.parseFromText(config_string);
   easyloggingpp::Loggers::reconfigureAllLoggers(confFromFile);
}

then call :

initializeLogs("*GLOBAL:\nFILENAME = my_app.log\nFORMAT = %datetime{%Y.%M.%d-%H.%m.%s.%g}, %level, %msg\n*INFO:\n ENABLED=false");