CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2016
    Posts
    1

    log4cpp not rolling after reaching maxFileSize

    Due to some reasons or some configuration error, the log4cpp that i am using for my application is not rolling the file after reaching the maxFileSize mentioned. I have tried to internally configure log4cpp. Following is the source file used for logging:

    //logger.cpp
    #include"logger.h"

    int logInit(int prio){
    log4cpp::Appender * appender2 = new log4cpp::RollingFileAppender("default","../logs/log.log", 300*1024*1024, 20);
    log4cpp::PatternLayout *layout = new log4cpp::PatternLayout();
    layout->setConversionPattern(std::string("%d [%t] %-5p %c - %m%n%n%n"));
    appender2->setLayout(layout);
    sub1.addAppender(appender2);

    switch(prio){
    case 0:
    sub1.setPriority(0);
    break;

    case 1 :
    sub1.setPriority(log4cpp::Priority::ERROR);
    break;
    case 2 :
    sub1.setPriority(log4cpp::Priority::INFO);
    break;
    case 3 :
    sub1.setPriority(log4cpp::Priority:EBUG);
    break;
    default :
    sub1.setPriority(log4cpp::Priority::EMERG);
    }
    return 0;

    }
    And following is the header file corresponding to the source file:

    //logger.h
    #ifndef _LOGHNDL_H
    #define _LOGHNDL_H

    #include "log4cpp/Category.hh"
    #include "log4cpp/Appender.hh"
    #include "log4cpp/FileAppender.hh"
    #include "log4cpp/OstreamAppender.hh"
    #include "log4cpp/Layout.hh"
    #include "log4cpp/BasicLayout.hh"
    #include "log4cpp/Priority.hh"
    #include "log4cpp/PropertyConfigurator.hh"
    #include "log4cpp/RollingFileAppender.hh"
    #include "log4cpp/PatternLayout.hh"


    #define error log4cpp::Priority::ERROR
    #define debug log4cpp::Priority:EBUG
    #define info log4cpp::Priority::INFO
    extern log4cpp::Category& sub1;

    int logInit(int);
    #endif
    And following is the way in which the logger is initialized at application start:

    //main.cpp
    #include "logger.h"
    log4cpp::Category& sub1=log4cpp::Category::getInstance(std::string("LOG"));
    int main(){
    logInit(3);
    }
    I am relatively new to programming in C++, can someone please help me? Thanks!

  2. #2
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: log4cpp not rolling after reaching maxFileSize

    Please, repost your code using the CODE tags and proper indentations.
    Otherwise this code is absolutely unreadable!
    See also the Announcement: Before you post....
    Victor Nijegorodov

  3. #3
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: log4cpp not rolling after reaching maxFileSize

    [moved from Visual C++ Bugs & Fixes forum]
    Victor Nijegorodov

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured