easyloggingpp icon indicating copy to clipboard operation
easyloggingpp copied to clipboard

Easylogging++ Rolling doesn't work properly

Open rootex- opened this issue 10 years ago • 1 comments

It appears that Easylogging++ Rolling doesn't work properly. The following program writes chars from 'a' to 'p' to 5 files (0.log, 1.log, 2.log, 3.log, 4.log). Each file has a size limited to 8 bytes, 4 characters per each file (including line breaks). For instance,

File "0.log" has to be

a b c d

File "1.log" has to be

d e f g

And so on...

The problem is the result I get. It is weird.

Result:

0.log = {n o p a} -- WTF?? 1.log = {b c d e} -- WTF?? 2.log = {f g h i} -- WTF?? 3.log = {j k l m} -- WTF?? 4.log = (not yet created)

But the correct result I am waiting for is:

0.log = {a b c d} 1.log = {e f g h} 2.log = {i j k l} 3.log = {m n o p} 4.log = (not yet created)

What is the problem?

main.cpp

#include <QCoreApplication>
#include <iostream>
#include "easylogging++.h"
using namespace std;

INITIALIZE_EASYLOGGINGPP

void LogsRollout(const char* fname, size_t fsize);
int log_sequence = 0;

int main(int argc, char *argv[])
{
    // Import basic configurations
    el::Loggers::configureFromGlobal("config.conf");
    el::Loggers::addFlag(el::LoggingFlag::StrictLogFileSizeCheck);

    // The filesize is limited to 8 bytes: 4 letters per each file + 4 line breaks = 8 bytes filesize
    el::Loggers::reconfigureAllLoggers(el::ConfigurationType::MaxLogFileSize, "8");
    el::Helpers::installPreRollOutCallback(LogsRollout);

    // Add letters to files
    for(int i = 'a'; i <= 'p'; i++)
    {
    LOG(INFO) << (char) i;
    }

    return 0;
}


// ----------------------------------------------------------------------------------------------------------
// LogsRollout function
// ----------------------------------------------------------------------------------------------------------
void LogsRollout(const char* fname, size_t fsize)
{
    // Filenames from 0 to 4 (0.log, 1.log, 2.log, 3.log, 4.log)
    if (log_sequence >= 5)
    {
    log_sequence = 0;
    }

    // Rename the file
    std::string str = "";
    str += std::to_string(log_sequence);
    str += ".log";
    rename(fname, str.c_str());

    log_sequence++;
}

config.conf

    -- default

* GLOBAL:
    TO_FILE         = true
    FORMAT          = "%msg"
    TO_STANDARD_OUTPUT  = true
    PERFORMANCE_TRACKING    = true
    ENABLED         = true


* INFO:
    TO_STANDARD_OUTPUT  = true

* TRACE:
    TO_STANDARD_OUTPUT  = true

* WARNING:
    TO_STANDARD_OUTPUT  = false
    TO_FILE         = false

* ERROR:
    TO_STANDARD_OUTPUT  = true

* FATAL:
    TO_STANDARD_OUTPUT  = true

* DEBUG:
    TO_STANDARD_OUTPUT  = true
    FORMAT          = "%msg"

rootex- avatar May 05 '15 12:05 rootex-

This sample program works correctly for me and I get the correct output (Easylogging++ v9.97.0 and compiled with g++ 9.4.0).

simoc avatar Apr 02 '22 14:04 simoc