示例#1
0
static void
test_sigsafe_err(void *arg)
{
  const char *fn=get_fname("sigsafe_err_log");
  char *content=NULL;
  log_severity_list_t include_bug;
  smartlist_t *lines = smartlist_new();
  (void)arg;

  set_log_severity_config(LOG_WARN, LOG_ERR, &include_bug);

  init_logging(1);
  mark_logs_temp();
  add_file_log(&include_bug, fn, 0);
  tor_log_update_sigsafe_err_fds();
  close_temp_logs();

  close(STDERR_FILENO);
  log_err(LD_BUG, "Say, this isn't too cool.");
  tor_log_err_sigsafe("Minimal.\n", NULL);

  set_log_time_granularity(100*1000);
  tor_log_err_sigsafe("Testing any ",
                      "attempt to manually log ",
                      "from a signal.\n",
                      NULL);
  mark_logs_temp();
  close_temp_logs();
  close(STDERR_FILENO);
  content = read_file_to_str(fn, 0, NULL);

  tt_assert(content != NULL);
  tor_split_lines(lines, content, (int)strlen(content));
  tt_int_op(smartlist_len(lines), OP_GE, 5);

  if (strstr(smartlist_get(lines, 0), "opening new log file"))
    smartlist_del_keeporder(lines, 0);
  tt_assert(strstr(smartlist_get(lines, 0), "Say, this isn't too cool"));
  /* Next line is blank. */
  tt_assert(!strcmpstart(smartlist_get(lines, 1), "=============="));
  tt_assert(!strcmpstart(smartlist_get(lines, 2), "Minimal."));
  /* Next line is blank. */
  tt_assert(!strcmpstart(smartlist_get(lines, 3), "=============="));
  tt_str_op(smartlist_get(lines, 4), OP_EQ,
            "Testing any attempt to manually log from a signal.");

 done:
  tor_free(content);
  smartlist_free(lines);
}
示例#2
0
 logger::logger()
 {
   const configuration& conf = configuration::instance();
   boost::log::register_simple_formatter_factory< boost::log::trivial::severity_level, char >("Severity");
   add_common_attributes();
   add_file_log(keywords::file_name = conf.get(configuration::LOG_DIR)->second + '/' + conf.get(configuration::LOG_FILE)->second, 
              keywords::rotation_size = 10 * 1024 * 1024,
              keywords::time_based_rotation = sinks::file::rotation_at_time_point(0, 0, 0),
              keywords::format = "<%Severity%> [%TimeStamp%]: %Message%",
              keywords::auto_flush = true
             );
   string logLevel = conf.get(configuration::LOG_LEVEL)->second;
   if ("TRACE" == logLevel)
   {
     core::get()->set_filter(trivial::severity >= trivial::trace);
   }
   else if ("DEBUG" == logLevel)
   {
     core::get()->set_filter(trivial::severity >= trivial::debug);
   }
   else if ("INFO" == logLevel)
   {
     core::get()->set_filter(trivial::severity >= trivial::info);
   }
   else if ("WARNING" == logLevel)
   {
     core::get()->set_filter(trivial::severity >= trivial::warning);
   }
   else if ("ERROR" == logLevel)
   {
     core::get()->set_filter(trivial::severity >= trivial::error);
   }
   else if ("FATAL" == logLevel)
   {
     core::get()->set_filter(trivial::severity >= trivial::fatal);
   }
   else 
   {
     core::get()->set_filter(trivial::severity >= trivial::info);
   }
 }