easyloggingpp icon indicating copy to clipboard operation
easyloggingpp copied to clipboard

Problem with installCustomFormatSpecifier.

Open Kuzma30 opened this issue 1 year ago • 2 comments

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.

Kuzma30 avatar Oct 11 '23 05:10 Kuzma30

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.

abumq avatar Oct 28 '23 01:10 abumq

Yes, I have the same problem

yalov avatar May 30 '24 06:05 yalov