Beispiel #1
0
int CommInpCfg :: redirectLog ()
{
    time_t      curr_t;
    struct tm  *ptm;
    char        log_file_name[32];

    time (&curr_t);
    ptm = gmtime (&curr_t);
    strftime (log_file_name, 32, "%Y%m%d_%H%M%S.log", ptm);

    string AppLogFile(dataOpt__.WorkingPath);
    AppLogFile.append("/")
    .append(log_file_name);

    Category& rootLogCategory = Category::getRoot();
    rootLogCategory.removeAllAppenders();

    Appender* appender = new FileAppender("Log", AppLogFile);
    PatternLayout* patternLayout = new PatternLayout();
    patternLayout->setConversionPattern("[%d{%Y:%m:%d %H:%M:%S.%I}] %p %c %x: %m%n");
    Layout* layout = dynamic_cast<Layout*> (patternLayout);
    appender->setLayout(layout);

    cout << "Redirecting logging from stdout to : " << AppLogFile << endl;
    rootLogCategory.addAppender(appender);

    return 0;
}
Beispiel #2
0
void HttpLog::init()
{

    s_pLogger = Logger::getRootLogger() ;
    new(achAccessLog) AccessLog("");
    Appender *appender
        = Appender::getAppender("stderr", "appender.ps");
    Layout *layout = Layout::getLayout(ERROR_LOG_PATTERN, "layout.pattern");
    layout->setUData(s_logPattern);
    appender->setLayout(layout);
    logger()->setLevel(Level::DEBUG);
    logger()->setAppender(appender);
}
Beispiel #3
0
CommInpCfg :: CommInpCfg()
{
    // Set up logging with stdout as destination
    Category& rootLogCategory = Category::getRoot();
    rootLogCategory.setPriority(Priority::INFO);
    rootLogCategory.removeAllAppenders();

    Appender* appender = new FileAppender("_", dup(fileno(stdout)));
    PatternLayout* patternLayout = new PatternLayout();
    patternLayout->setConversionPattern("[%d{%Y:%m:%d %H:%M:%S.%I}] %p %c %x: %m%n");
    Layout* layout = dynamic_cast<Layout*> (patternLayout);
    appender->setLayout(layout);

    rootLogCategory.addAppender(appender);
}
Beispiel #4
0
static log4cxx::Logger* initLogger(const char* logFile, const char* logLevel)
{
    static char s_parttern[] = "%d [%p] [%c] %m";
    using namespace LOG4CXX_NS;    
    Logger *pLogger = Logger::getRootLogger() ;
    Appender * appender
    = Appender::getAppender( logFile, "appender.ps" );
    Layout* layout = Layout::getLayout( "patternErrLog", "layout.pattern" );
    layout->setUData( s_parttern );
    appender->setLayout( layout );
    log4cxx::Level::setDefaultLevel(Level::toInt(logLevel));
    pLogger->setLevel( logLevel );
    pLogger->setAppender( appender );
    return pLogger;
}
Beispiel #5
0
int HttpLog::setErrorLogFile(const char *pFileName)
{
    Appender *appender
        = Appender::getAppender(pFileName, "appender.ps");
    if (appender)
    {
        Appender *pOld = logger()->getAppender();
        if ((pOld) && (pOld != appender))
            pOld->close();
        Layout *layout = Layout::getLayout(ERROR_LOG_PATTERN, "layout.pattern");
        appender->setLayout(layout);
        logger()->setAppender(appender);
        return 0;
    }
    else
        return LS_FAIL;
}
Beispiel #6
0
void initialize_log(const char* name, int verbose, string const& file_log = "")
{
    // 1 instantiate an appender object that 
    // will append to a log file
    Appender* app;
    if (file_log.empty())
        app = new OstreamAppender(name, &std::cout);
    else 
        app = new FileAppender(name, file_log);

    // 2. Instantiate a layout object
    // Two layouts come already available in log4cpp
    // unless you create your own.
    // BasicLayout includes a time stamp
    Layout* layout = new BasicLayout();

    // 3. attach the layout object to the 
    // appender object
    app->setLayout(layout);

    // 4. Instantiate the category object
    // you may extract the root category, but it is
    // usually more practical to directly instance
    // a child category
    Category * main_cat = &Category::getInstance(name);

    // 5. Step 1 
    // an Appender when added to a category becomes
    // an additional output destination unless 
    // Additivity is set to false when it is false,
    // the appender added to the category replaces
    // all previously existing appenders
    main_cat->setAdditivity(false);

    // 5. Step 2
    // this appender becomes the only one
    main_cat->setAppender(app);

    // 6. Set up the priority for the category
    // and is given INFO priority
    // attempts to log DEBUG messages will fail
    main_cat->setPriority( verbose*100 );
}
Beispiel #7
0
Appender * Appender::getAppender(com_device_t &dev)
{
	xAutoLock lock(&comlog_appender_getlock);

	//devµÄ²ÎÊý¼ì²é
	__CHECKINT(dev.log_size, 1, COM_MAXLOGFILE, COM_MAXLOGFILE);
	
	Appender *app = NULL; 
	switch (dev.type) {
		case COM_FILEDEVICE:
			_com_debug("create file appender");
			app = FileAppender::getAppender(dev);
			break;
		case COM_NETDEVICE:
			_com_debug("create net appender");
			app = NetAppender::getAppender(dev);
			break;
		case COM_TTYDEVICE:
			_com_debug("create tty appender");
			app = TtyAppender::getAppender(dev);
			break;
		case COM_ULLOGDEVICE:
		case COM_ULNETDEVICE:
			_com_debug("create ul appender");
			app = UlLogAppender::getAppender(dev);
			break;
		case COM_AFILEDEVICE:
			_com_debug("create async file appender");
			app = AsyncFileAppender::getAppender(dev);
			break;
		default:
			_com_error("sorry i can't know the type[%d]", dev.type);
			break;
	}
	if (app != NULL) {
		app->setLayout(dev.layout);
		_core_debug("dev =%lx appender layout=%lx", dev.layout, app->_layout);
		app->_open = dev.open;
	}

	return app;
}