abumq / easyloggingpp

C++ logging library. It is powerful, supports asynchronous low latency, 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.78k stars 924 forks source link

How to make path of log file in the config relative to exe folder, but not the active folder? #847

Open yalov opened 11 months ago

yalov commented 11 months ago

I can get the abs_path of the folder of exe in the code, and prepend it to the log path in global config:

    el::Loggers::configureFromGlobal((get_folder_of_exe() / "easylogging++.conf").string().c_str());

    // update path of the main log file to be not relative to active folder, but to the folder of exe
    auto logger = el::Loggers::getLogger("default");
    std::string abs_filepath = (get_folder_of_exe() / logger->typedConfigurations()->filename(el::Level::Info)).string();

    logger->configurations()->setGlobally(el::ConfigurationType::Filename, abs_filepath);
    logger->reconfigure();

but:

P.S. "active folder" is different from the "exe folder" if I try to launch exe in the console from a different location.