1

我正在我的项目中实施 log4cpp。请参阅我在项目中实现的 Logger 类。它在文件中doConfigure(initfile)定义的函数中崩溃。PropertyConfiguratorImpl.cpp更具体地说,在调用log4cpp 文件的函数调用_properties.load(in)中:Propertices.cpp

 void Properties::load(std::istream& in)//_Chcount=0 in the expression value
 {
    clear();

    std::string fullLine, command;
    std::string leftSide, rightSide;
    char line[256];
    std::string::size_type length;

    while (in.getline(line, 256)) {
        fullLine = line;
................
.................//Remaining code of the function
..................
}

下面是我的记录器类。它在我的项目中实现

class MyLogger
{
public:
MyLogger(){}
virtual ~MyLogger() {
    log4cpp::Category::shutdown();
}
bool Init(){
    try{
        std::string initFileName = "log4cpp.property";
        if(exists(initFileName.c_str())){//the property file does exist
            log4cpp::PropertyConfigurator::configure(initFileName);
        }           
    }
    catch(log4cpp::ConfigureFailure& f){
        std::cout << "Configure Problem" << f.what() << std::endl;
        return false;
    }
    return true;
}
void LogDebug(std::string message){
    log4cpp::Category & myLogger = log4cpp::Category::getInstance("MyLogger");
    myLogger.debug(message);
}

void Loginfo(std::string message){
    log4cpp::Category & myLogger = log4cpp::Category::getInstance("MyLogger");
    myLogger.info(message);
}
};

这是我的 log4cpp.property 文件:

log4cplus.logger.business=ALL,BUSINESS
log4cplus.additivity.business=false

log4cplus.appender.STDOUT=log4cplus::ConsoleAppender
log4cplus.appender.STDOUT.layout=log4cplus::PatternLayout
log4cplus.appender.STDOUT.layout.ConversionPattern=%-6p[%t][%D{%m/%d/%y %H:%M:%S %Q}]%m

log4cplus.appender.BUSINESS=log4cplus::RollingFileAppender
log4cplus.appender.BUSINESS.File=./all.log
log4cplus.appender.BUSINESS.MaxFileSize=5MB
log4cplus.appender.BUSINESS.MaxBackupIndex=5
log4cplus.appender.BUSINESS.layout=log4cplus::PatternLayout
log4cplus.appender.BUSINESS.layout.ConversionPattern=%-6p[%t] [%D{%m/%d/%y %H:%M:%S %Q}] %m

任何帮助表示赞赏。

4

0 回答 0