Giter Club home page Giter Club logo

Comments (4)

wilx avatar wilx commented on June 18, 2024

I think this is by design. DailyRollingFileAppender does the same thing since ever (5b6b25a). TimeBasedRollingFileAppender is new and it has inherited the feature from DailyRollingFileAppender. The idea is that if you do not roll the file when you are closing the appender, you will not know what file name to use next time you start your application and need to roll it.

from log4cplus.

artur-shaik avatar artur-shaik commented on June 18, 2024

For me, it looks like a bug, too.

    const char* logPath = logDir.append("%d.log").toStdString().c_str();

    initialize();

    helpers::Properties p;
    p.setProperty(LOG4CPLUS_TEXT("FilenamePattern"), LOG4CPLUS_TEXT(logPath));
    p.setProperty(LOG4CPLUS_TEXT("CleanHistoryOnStart"), LOG4CPLUS_TEXT("false"));
    p.setProperty(LOG4CPLUS_TEXT("CreateDirs"), LOG4CPLUS_TEXT("true"));
    p.setProperty(LOG4CPLUS_TEXT("ImmediateFlush"), LOG4CPLUS_TEXT("true"));
    p.setProperty(LOG4CPLUS_TEXT("DatePattern"), LOG4CPLUS_TEXT("yyyy-MM-dd"));

    const char* pattern = "%-7r [%d{%Y/%m%dT%H:%M:%S.%Q}] %5p [%10.10t] %c <> %m%n";
    SharedTimeBasedRollingFileAppenderPtr fileAppender(new TimeBasedRollingFileAppender(p));
    fileAppender->setName(LOG4CPLUS_TEXT("FileAppender"));
    fileAppender->setLayout(std::auto_ptr<Layout>(new PatternLayout(pattern)));
    Logger::getRoot().addAppender(SharedAppenderPtr(fileAppender.get()));

    if (verbose)
    {
        helpers::SharedObjectPtr<Appender> consoleAppender(new ConsoleAppender());
        consoleAppender->setLayout(std::auto_ptr<Layout>(new PatternLayout(pattern)));
        consoleAppender->setName(LOG4CPLUS_TEXT("ConsoleAppender"));
        Logger::getRoot().addAppender(consoleAppender);
    }

    Logger::getRoot().setLogLevel(getLogLevel(level));

With this setup, on exit log file always empty.

If I add:

    p.setProperty(LOG4CPLUS_TEXT("Filename"), LOG4CPLUS_TEXT(filePath));

On exit patterned log file is always overwrited. Doesn't append to old log file.

Or may be this is wrong approach?

PS For now I have removed rollover call in close() method, and it works as expected for me.

from log4cplus.

sangechen avatar sangechen commented on June 18, 2024

I had fix this problem using:

  1. remove rollover() call in close() {TimeBasedRollingFileAppender do not need this rollover behavior, I think}
  2. after rotate log files, re-open new file, do not truncate it! {when File property is missing, TimeBasedRollingFileAppender do not rollover at all. so we cannot truncate any file}

from log4cplus.

wilx avatar wilx commented on June 18, 2024

I think this is now fixed by #123.

from log4cplus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.