Example #1
0
bool Log::open_log()
{
	std::string level;
	if (!Config::instance().get_str_conf("log_level", level)) {
		std::cout << "Can not get log_level in configuration file!" << std::endl;
		return false;
	}
	LogLevel Log_level = string_to_log_level(level);

	/* step 1: Instantiate an appender object */
	SharedAppenderPtr _append(new RollingFileAppender(LOG_FILE_NAME, 1000*1024, 5));
	_append->setName("file log test");

	/* step 2: Instantiate a layout object */
	std::string pattern = "[%p] [%D{%m/%d/%y %H:%M:%S}] [%l] - %m %n";
	std::auto_ptr<Layout> _layout(new PatternLayout(pattern));

	/* step 3: Attach the layout object to the appender */
	_append->setLayout(_layout);

	/* step 4: Instantiate a logger object */

	/* step 5: Attach the appender object to the logger  */
	_logger.addAppender(_append);

	/* step 6: Set a priority for the logger  */
	_logger.setLogLevel(Log_level);

	return true;
}
Example #2
0
/*!

\brief Constructor.
\param[in] AppName String containing unit test name.
\param[in] argc Number of arguments in argv
\param[in] argv Array of char arrays containing the command line arguments.

*/
dmz::Test::Test (const String &AppName, int argc, char *argv[]) :
      obs (rt.get_context ()),
      config ("global"),
      log ("", rt.get_context ()),
      error (False) {

   const String LogLevelEnvStr (get_env ("DMZ_TEST_LOG_LEVEL"));
   LogLevelEnum level (LogLevelWarn);
   if (LogLevelEnvStr) { level = string_to_log_level (LogLevelEnvStr); }
   obs.set_level (level);

   log.out
      << "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-" << endl
      << "Running " << AppName << " unit test." << endl
      << "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-" << endl;

   CommandLine cl (argc, argv);
   CommandLineConfig clconfig;

   if (!clconfig.process_command_line (cl, config)) {

      log.error << "Unable to process command line: " << clconfig.get_error () << endl;
      error = True;
   }
}
int cf_opt_log_level(int *levelp, const char *text)
{
  int level = string_to_log_level(text);
  if (level == LOG_LEVEL_INVALID)
    return CFINVALID;
  *levelp = level;
  return CFOK;
}