Ejemplo n.º 1
0
int main(int argc, char ** argv) {
  LoggerPtr logger = Logger::getLogger("main");
  Memkeys * app = NULL;
  int rc = EXIT_SUCCESS;

  logger->setLevel(Level::INFO);

  // configure and initialize the app
  try {
    app = Memkeys::getInstance(argc, argv);
  } catch(...) {
    return handleConfigurationError(logger, argv[0]);
  }

  // run the app
  try {
    app->run();
  } catch (const exception &ex) {
    logger->fatal(CONTEXT, "Error running application: %s", ex.what());
    rc = EXIT_FAILURE;
  }
  logger->info(CONTEXT, "Shutting down");

  // handle cleanup
  delete logger;
  delete app;
  delete Config::getInstance();
  delete Logger::getRootLogger();
  return rc;
}
Ejemplo n.º 2
0
// Used for initializing app main()
Memkeys * Memkeys::getInstance(int argc, char ** argv)
{
  Config * cfg = Config::getInstance();
  LoggerPtr mainLogger = Logger::getLogger("main");
  try {
    Cli::parse(argc, argv, cfg);
  } catch (const exception &ex) {
    throw MemkeysConfigurationError(ex.what());
  }
  mainLogger->setLevel(Level::INFO);
  mainLogger->info(CONTEXT,
                   "Starting application %s. PID %d", argv[0], getpid());
  Logger::getRootLogger()->setLevel(cfg->verbosity());
  mainLogger->debug("Configuration\n" + cfg->toString());
  return Memkeys::getInstance(cfg);
}
Ejemplo n.º 3
0
LoggerPtr Logger::getLogger(const string &name)
{
  Loggers::iterator it = loggers.find(name);
  if (it != loggers.end()) {
    return it->second;
  } else {
    LoggerPtr logger = new Logger(name);
    if (!logger->isRootLogger()) {
      LoggerPtr root = Logger::getRootLogger();
      logger->setParent(root);
      logger->setUseParent(true);
      logger->setLevel(root->getLevel());
    }
    logger->trace("Created logger");
    loggers.insert(it, Loggers::value_type(name, logger));
    return logger;
  }
}
Ejemplo n.º 4
0
      /**
       * sets the root level for the logger. 
       */
      void Log4cxxLogger::setLevel(std::string esyslog, LoggerPtr rootLogger){
	
	//LoggerPtr rootLogger = Logger::getRootLogger();
	if (esyslog == "debug"){
	  
	  rootLogger->setLevel(Level::DEBUG);
	}
	else if (esyslog == "info")
	  
	  rootLogger->setLevel(Level::INFO);
	
	else if (esyslog == "notice")
	  
	  rootLogger->setLevel(Level::INFO);	
	else if (esyslog == "warning"){
	  rootLogger->setLevel(Level::WARN);
	}
	else if (esyslog == "err"){
	  rootLogger->setLevel(Level::ERROR);
	}
	else if (esyslog == "crit")
	  
	  rootLogger->setLevel(Level::FATAL);
	
	else if (esyslog == "alert")
	  rootLogger->setLevel(Level::WARN);
	
	else if (esyslog == "emerg")
	  rootLogger->setLevel(Level::FATAL);
	
	else {
	  rootLogger->setLevel(Level::INFO);
	  rootLogger->error("Unknown syslog level: " + esyslog); 
	}
	
      }
Ejemplo n.º 5
0
void Server::setupLogging() {
	using namespace boost;
	using namespace log4cxx;
	using namespace log4cxx::helpers;
	using namespace log4cxx::xml;

	LoggerPtr rootLogger = Logger::getRootLogger();
	rootLogger->addAppender(new ConsoleAppender(new PatternLayout("%d | %5p | %m%n")));
	rootLogger->setLevel(Level::getDebug());

	bool directoryCreationFailed = false;
	bool configurationFileMissing = false;

	if (!filesystem::is_directory(LOGGING_DIRECTORY)) {
		system::error_code error;
		if (filesystem::create_directory(LOGGING_DIRECTORY, error)) {
			chmod(LOGGING_DIRECTORY.c_str(), S_IRWXU);
		}
		else {
			directoryCreationFailed = true;
		}
	}

	// sadly we cannot check whether we were successful or not :(
	if (filesystem::is_regular_file(LOGGING_CONFIGURATION_FILE) || filesystem::is_symlink(LOGGING_CONFIGURATION_FILE)) {
		DOMConfigurator::configureAndWatch(LOGGING_CONFIGURATION_FILE);
	}
	else {
		configurationFileMissing = true;
	}

	LOGi(std::setfill('-') << std::setw(90) << "");
	LOGi(SOFTWARE_NAME " " SOFTWARE_VERSION " for Tibia(R) " SOFTWARE_PROTOCOL);
	LOGi(X_PROJECT_URL);
	LOGi(std::setfill('-') << std::setw(90) << "");

	if (configurationFileMissing) {
		LOGe("Cannot find logging configuration file '" << LOGGING_CONFIGURATION_FILE << "'. Using defaults.");
	}
	if (directoryCreationFailed) {
		LOGe("Cannot create logging directory '" << LOGGING_DIRECTORY << "'. No log files will be written.");
	}
}
Ejemplo n.º 6
0
	void common()
	{
		int i = 0;

		// In the lines below, the category names are chosen as an aid in
		// remembering their level values. In general, the category names
		// have no bearing to level values.
		LoggerPtr ERR = Logger::getLogger(_T("ERR"));
		ERR->setLevel(Level::ERROR);

		LoggerPtr INF = Logger::getLogger(_T("INF"));
		INF->setLevel(Level::INFO);

		LoggerPtr INF_ERR = Logger::getLogger(_T("INF.ERR"));
		INF_ERR->setLevel(Level::ERROR);

		LoggerPtr DEB = Logger::getLogger(_T("DEB"));
		DEB->setLevel(Level::DEBUG);

		// Note: categories with undefined level
		LoggerPtr INF_UNDEF = Logger::getLogger(_T("INF.UNDEF"));
		LoggerPtr INF_ERR_UNDEF = Logger::getLogger(_T("INF.ERR.UNDEF"));
		LoggerPtr UNDEF = Logger::getLogger(_T("UNDEF"));

		// These should all log.----------------------------
		LOG4CXX_FATAL(ERR, _T("Message ") << i);
		i++; //0
		LOG4CXX_ERROR(ERR, _T("Message ") << i);
		i++;

		LOG4CXX_FATAL(INF, _T("Message ") << i);
		i++; // 2
		LOG4CXX_ERROR(INF, _T("Message ") << i);
		i++;
		LOG4CXX_WARN(INF, _T("Message ") << i);
		i++;
		LOG4CXX_INFO(INF, _T("Message ") << i);
		i++;

		LOG4CXX_FATAL(INF_UNDEF, _T("Message ") << i);
		i++; //6
		LOG4CXX_ERROR(INF_UNDEF, _T("Message ") << i);
		i++;
		LOG4CXX_WARN(INF_UNDEF, _T("Message ") << i);
		i++;
		LOG4CXX_INFO(INF_UNDEF, _T("Message ") << i);
		i++;

		LOG4CXX_FATAL(INF_ERR, _T("Message ") << i);
		i++; // 10
		LOG4CXX_ERROR(INF_ERR, _T("Message ") << i);
		i++;

		LOG4CXX_FATAL(INF_ERR_UNDEF, _T("Message ") << i);
		i++;
		LOG4CXX_ERROR(INF_ERR_UNDEF, _T("Message ") << i);
		i++;

		LOG4CXX_FATAL(DEB, _T("Message ") << i);
		i++; //14
		LOG4CXX_ERROR(DEB, _T("Message ") << i);
		i++;
		LOG4CXX_WARN(DEB, _T("Message ") << i);
		i++;
		LOG4CXX_INFO(DEB, _T("Message ") << i);
		i++;
		LOG4CXX_DEBUG(DEB, _T("Message ") << i);
		i++;

		// defaultLevel=DEBUG
		LOG4CXX_FATAL(UNDEF, _T("Message ") << i);
		i++; // 19
		LOG4CXX_ERROR(UNDEF, _T("Message ") << i);
		i++;
		LOG4CXX_WARN(UNDEF, _T("Message ") << i);
		i++;
		LOG4CXX_INFO(UNDEF, _T("Message ") << i);
		i++;
		LOG4CXX_DEBUG(UNDEF, _T("Message ") << i);
		i++;

		// -------------------------------------------------
		// The following should not log
		LOG4CXX_WARN(ERR, _T("Message ") << i);
		i++;
		LOG4CXX_INFO(ERR, _T("Message ") << i);
		i++;
		LOG4CXX_DEBUG(ERR, _T("Message ") << i);
		i++;

		LOG4CXX_DEBUG(INF, _T("Message ") << i);
		i++;
		LOG4CXX_DEBUG(INF_UNDEF, _T("Message ") << i);
		i++;

		LOG4CXX_WARN(INF_ERR, _T("Message ") << i);
		i++;
		LOG4CXX_INFO(INF_ERR, _T("Message ") << i);
		i++;
		LOG4CXX_DEBUG(INF_ERR, _T("Message ") << i);
		i++;
		LOG4CXX_WARN(INF_ERR_UNDEF, _T("Message ") << i);
		i++;
		LOG4CXX_INFO(INF_ERR_UNDEF, _T("Message ") << i);
		i++;
		LOG4CXX_DEBUG(INF_ERR_UNDEF, _T("Message ") << i);
		i++;

		// -------------------------------------------------
		LOG4CXX_INFO(INF, _T("Messages should bear numbers 0 through 23."));
	}
Ejemplo n.º 7
0
    void common()
    {
        int i = 0;

        // In the lines below, the logger names are chosen as an aid in
        // remembering their level values. In general, the logger names
        // have no bearing to level values.
        LoggerPtr ERRlogger = Logger::getLogger(LOG4CXX_TEST_STR("ERR"));
        ERRlogger->setLevel(Level::getError());

        LoggerPtr INF = Logger::getLogger(LOG4CXX_TEST_STR("INF"));
        INF->setLevel(Level::getInfo());

        LoggerPtr INF_ERR = Logger::getLogger(LOG4CXX_TEST_STR("INF.ERR"));
        INF_ERR->setLevel(Level::getError());

        LoggerPtr DEB = Logger::getLogger(LOG4CXX_TEST_STR("DEB"));
        DEB->setLevel(Level::getDebug());

        // Note: categories with undefined level
        LoggerPtr INF_UNDEF = Logger::getLogger(LOG4CXX_TEST_STR("INF.UNDEF"));
        LoggerPtr INF_ERR_UNDEF = Logger::getLogger(LOG4CXX_TEST_STR("INF.ERR.UNDEF"));
        LoggerPtr UNDEF = Logger::getLogger(LOG4CXX_TEST_STR("UNDEF"));

        std::string msg("Message ");

        Pool pool;

        // These should all log.----------------------------
        LOG4CXX_FATAL(ERRlogger, createMessage(i, pool));
        i++; //0
        LOG4CXX_ERROR(ERRlogger, createMessage(i, pool));
        i++;

        LOG4CXX_FATAL(INF, createMessage(i, pool));
        i++; // 2
        LOG4CXX_ERROR(INF, createMessage(i, pool));
        i++;
        LOG4CXX_WARN(INF, createMessage(i, pool));
        i++;
        LOG4CXX_INFO(INF, createMessage(i, pool));
        i++;

        LOG4CXX_FATAL(INF_UNDEF, createMessage(i, pool));
        i++; //6
        LOG4CXX_ERROR(INF_UNDEF, createMessage(i, pool));
        i++;
        LOG4CXX_WARN(INF_UNDEF, createMessage(i, pool));
        i++;
        LOG4CXX_INFO(INF_UNDEF, createMessage(i, pool));
        i++;

        LOG4CXX_FATAL(INF_ERR, createMessage(i, pool));
        i++; // 10
        LOG4CXX_ERROR(INF_ERR, createMessage(i, pool));
        i++;

        LOG4CXX_FATAL(INF_ERR_UNDEF, createMessage(i, pool));
        i++;
        LOG4CXX_ERROR(INF_ERR_UNDEF, createMessage(i, pool));
        i++;

        LOG4CXX_FATAL(DEB, createMessage(i, pool));
        i++; //14
        LOG4CXX_ERROR(DEB, createMessage(i, pool));
        i++;
        LOG4CXX_WARN(DEB, createMessage(i, pool));
        i++;
        LOG4CXX_INFO(DEB, createMessage(i, pool));
        i++;
        LOG4CXX_DEBUG(DEB, createMessage(i, pool));
        i++;

        // defaultLevel=DEBUG
        LOG4CXX_FATAL(UNDEF, createMessage(i, pool));
        i++; // 19
        LOG4CXX_ERROR(UNDEF, createMessage(i, pool));
        i++;
        LOG4CXX_WARN(UNDEF, createMessage(i, pool));
        i++;
        LOG4CXX_INFO(UNDEF, createMessage(i, pool));
        i++;
        LOG4CXX_DEBUG(UNDEF, createMessage(i, pool));
        i++;

        // -------------------------------------------------
        // The following should not log
        LOG4CXX_WARN(ERRlogger, createMessage(i, pool));
        i++;
        LOG4CXX_INFO(ERRlogger, createMessage(i, pool));
        i++;
        LOG4CXX_DEBUG(ERRlogger, createMessage(i, pool));
        i++;

        LOG4CXX_DEBUG(INF, createMessage(i, pool));
        i++;
        LOG4CXX_DEBUG(INF_UNDEF, createMessage(i, pool));
        i++;

        LOG4CXX_WARN(INF_ERR, createMessage(i, pool));
        i++;
        LOG4CXX_INFO(INF_ERR, createMessage(i, pool));
        i++;
        LOG4CXX_DEBUG(INF_ERR, createMessage(i, pool));
        i++;
        LOG4CXX_WARN(INF_ERR_UNDEF, createMessage(i, pool));
        i++;
        LOG4CXX_INFO(INF_ERR_UNDEF, createMessage(i, pool));
        i++;
        LOG4CXX_DEBUG(INF_ERR_UNDEF, createMessage(i, pool));
        i++;

        // -------------------------------------------------
        LOG4CXX_INFO(INF, LOG4CXX_TEST_STR("Messages should bear numbers 0 through 23."));
    }