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

Problem with installCustomFormatSpecifier. #844

Open
Kuzma30 opened this issue Oct 11, 2023 · 2 comments
Open

Problem with installCustomFormatSpecifier. #844

Kuzma30 opened this issue Oct 11, 2023 · 2 comments

Comments

@Kuzma30
Copy link

Kuzma30 commented Oct 11, 2023

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
Copy link
Owner

abumq commented Oct 28, 2023

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
Copy link

yalov commented May 30, 2024

Yes, I have the same problem

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

3 participants