Пример #1
0
void Logger::setThresholdFromLoggingProperties(log4cplus::Logger logger) {
    // if logging.properties exists, attempt to set the
    // appropriate level for the given logger
    if (fileExists(PROP_FILE_LOC)) {
        Properties props(PROP_FILE_LOC);

        string loggerName = logger.getName();
        string logLevelKey = loggerName + ".level";
        if (props.isSet(logLevelKey)) {
            string level = props.get(logLevelKey);
            int l4cpLevel = log4cplus::getLogLevelManager().fromString(level);
            if (l4cpLevel != log4cplus::NOT_SET_LOG_LEVEL) {
                LOG4CPLUS_INFO(
                        logger,
                        LOG4CPLUS_TEXT(
                                "Configuring logger " + loggerName
                                + " with level " + level));
                logger.setLogLevel(l4cpLevel);
            } else {
                LOG4CPLUS_INFO(
                        logger,
                        LOG4CPLUS_TEXT(
                            "Unable to configure logger " + loggerName
                            + " with level " + level
                            + "; no such level found."));
            }
        }
    }
}
Пример #2
0
//---------------------------------------------------------//
void  CServer::initialize_logger(log4cplus::Logger& my_logger, IniReader::Section& section)
{
	using namespace log4cplus;
	
	my_logger.removeAllAppenders();

	std::string log_pattern;
	section.get_value("LOG_PATTERN", log_pattern, "%D{%c} [%t] [%p]: %m%n");

	std::string log_file_name;
	section.get_value("LOG_FILE_NAME", log_file_name, "Server.log");

	long log_parts;
	section.get_value("LOG_PARTS", log_parts, 3);

	long log_file_size;
	section.get_value("LOG_FILE_SIZE", log_file_size, 100);

	long log_level;
	section.get_value("LOG_LEVEL", log_level, long(log4cplus::FATAL_LOG_LEVEL));

	SharedAppenderPtr appender(new RollingFileAppender(	log_file_name, 
														log_file_size * 1024 * 1024, 
														log_parts));
	appender->setName(_T("log_appender"));
	appender->setLayout(std::auto_ptr<Layout>(new PatternLayout(log_pattern)));
	my_logger.setLogLevel(LogLevel(log_level));
	my_logger.addAppender(appender);
};
Пример #3
0
	bool CFileLogger::AddSameFileLogger(log4cplus::Logger& sublogger, log4cplus::Logger& mainlogger, int loglevel)
	{
		if ( &sublogger == &mainlogger )
		{
			return true;
		}

		SharedAppenderPtr append = mainlogger.getAppender(LOG4CPLUS_TEXT(GetFileAppenderName(mainlogger)));
		if (append)
		{
			sublogger.addAppender(append);
		}

		sublogger.setLogLevel(loglevel);

		return true;
	}
Пример #4
0
	bool CFileLogger::AddLogger(log4cplus::Logger& logger, const std::string& logpath, int loglevel)
	{
		if (!logpath.empty())
		{
			SharedAppenderPtr append(new DailyRollingFileAppender(LOG4CPLUS_TEXT(logpath), DAILY, true, 100));
			append->setName(LOG4CPLUS_TEXT(GetFileAppenderName(logger)));

			std::auto_ptr<Layout> layout(new PatternLayout(logpattern));
			append->setLayout(layout);

			logger.addAppender(append);
		}

		logger.setLogLevel(loglevel);

		return true;
	}
Пример #5
0
int
main()
{
  {
    //LoggerConfig();
  }
  Log::open("/home/jan.hoelscher/devel/mec/res");
  LOGDEBUG("twest");

    logger.setLogLevel(log4cplus::TRACE_LOG_LEVEL);
    cout << "*** calling printMessages() with TRACE set: ***" << endl;
    printMessages();

    logger.setLogLevel(log4cplus::DEBUG_LOG_LEVEL);
    cout << "\n*** calling printMessages() with DEBUG set: ***" << endl;
    printMessages();

    logger.setLogLevel(log4cplus::INFO_LOG_LEVEL);
    cout << "\n*** calling printMessages() with INFO set: ***" << endl;
    printMessages();

    logger.setLogLevel(log4cplus::WARN_LOG_LEVEL);
    cout << "\n*** calling printMessages() with WARN set: ***" << endl;
    printMessages();

    logger.setLogLevel(log4cplus::ERROR_LOG_LEVEL);
    cout << "\n*** calling printMessages() with ERROR set: ***" << endl;
    printMessages();

    logger.setLogLevel(log4cplus::FATAL_LOG_LEVEL);
    cout << "\n*** calling printMessages() with FATAL set: ***" << endl;
    printMessages();


  //log4cplus::Logger::shutdown();
    return 0;
}
Пример #6
0
	void CFileLogger::SetLogger(log4cplus::Logger& logger, int loglevel)
	{
		logger.setLogLevel(loglevel);
	}