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

Problem with installCustomFormatSpecifier. #844

Open Kuzma30 opened 11 months ago

Kuzma30 commented 11 months ago

I use such setup flow:


    QString filePath = ":/qml/test_conf.conf";

    QFile file(filePath);
    if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
        qDebug() << "Не вдалося відкрити файл для читання";
        return false;
    }

    QTextStream in(&file);
    QString fileContent = in.readAll();

    file.close();
    // Load configuration from file
    el::Configurations conf;
    conf.setToDefault();
    el::Helpers::installCustomFormatSpecifier(el::CustomFormatSpecifier("%session", getSession));  //programm run session
    conf.parseFromText(fileContent.toStdString());

    // Reconfigure single logger
    el::Loggers::reconfigureLogger("default", conf);
    // Actually reconfigure all loggers instead
    el::Loggers::reconfigureAllLoggers(conf);
    // Now all the loggers will use configuration from file
const char* getSession(const el::LogMessage*) {
    return "1";
}

test_conf.conf


* GLOBAL:
    FORMAT = %datetime{%h:%m:%s,%g} %level %session: %msg
    FILENAME = /tmp/logs/Ferti.%datetime{%Y%M%d}_%session.log
    ENABLED  = true
    TO_FILE  = true
    TO_STANDARD_OUTPUT  = true
    SUBSECOND_PRECISION = 6
    PERFORMANCE_TRACKING = false
    MAX_LOG_FILE_SIZE = 2097152 ## 2MB

Its work for LOG, but not work for FILENAME Example: 05:34:17,071665 INFO 1: Program Started It create /tmp/logs/Ferti.20231011_%session.log not /tmp/logs/Ferti.20231011_1.log

I need separate log file for new program run.

abumq commented 10 months ago

Thanks for this. The custom format specifier are only supported for the log message and not for the filenames as far as I remember.

Feel free to add a PR though. The code you or whoever works on it (i will do it if i get a chance) will be touching TypedConfigurations::resolveFilename in easyloggingpp.cc file.

If you work on this, please tag me in a comment in PR.

yalov commented 3 months ago

Yes, I have the same problem