Esempio n. 1
0
expected<std::unique_ptr<std::istream>>
make_input_stream(const caf::settings& options) {
  std::string category = Defaults::category;
  auto input = get_or(options, category + ".read", Defaults::read);
  auto uds = get_or(options, category + ".uds", false);
  return make_input_stream(input, uds);
}
Esempio n. 2
0
expected<std::unique_ptr<std::ostream>>
make_output_stream(const caf::settings& options) {
  std::string category = Defaults::category;
  auto output = get_or(options, category + ".write", Defaults::write);
  auto uds = get_or(options, category + ".uds", false);
  return make_output_stream(output, uds);
}
Esempio n. 3
0
void manager::stop() {
  CAF_LOG_TRACE("");
  scoped_actor self{system(), true};
  self->send_exit(manager_, exit_reason::kill);
  if (!get_or(config(), "middleman.attach-utility-actors", false))
    self->wait_for(manager_);
  manager_ = nullptr;
}
Esempio n. 4
0
void logger::start() {
#if CAF_LOG_LEVEL >= 0
  parent_thread_ = std::this_thread::get_id();
  if (level_ == CAF_LOG_LEVEL_QUIET)
    return;
  t0_ = make_timestamp();
  auto f = get_or(system_.config(), "logger.file-name",
                  defaults::logger::file_name);
  if (f.empty()) {
    // No need to continue if console and log file are disabled.
    if (has(console_output_flag))
      return;
  } else {
    // Replace placeholders.
    const char pid[] = "[PID]";
    auto i = std::search(f.begin(), f.end(), std::begin(pid),
                         std::end(pid) - 1);
    if (i != f.end()) {
      auto id = std::to_string(detail::get_process_id());
      f.replace(i, i + sizeof(pid) - 1, id);
    }
    const char ts[] = "[TIMESTAMP]";
    i = std::search(f.begin(), f.end(), std::begin(ts), std::end(ts) - 1);
    if (i != f.end()) {
      auto t0_str = timestamp_to_string(t0_);
      f.replace(i, i + sizeof(ts) - 1, t0_str);
    }
    const char node[] = "[NODE]";
    i = std::search(f.begin(), f.end(), std::begin(node), std::end(node) - 1);
    if (i != f.end()) {
      auto nid = to_string(system_.node());
      f.replace(i, i + sizeof(node) - 1, nid);
    }
    file_.open(f, std::ios::out | std::ios::app);
    if (!file_) {
      std::cerr << "unable to open log file " << f << std::endl;
      return;
    }
  }
  if (has(inline_output_flag))
    log_first_line();
  else
    thread_ = std::thread{[this] {
      this->system_.thread_started();
      this->run();
      this->system_.thread_terminates();
    }};
#endif
}
Esempio n. 5
0
void logger::log_first_line() {
  std::string msg = "level = ";
  msg += to_string(get_or(system_.config(), "logger.verbosity",
                          defaults::logger::verbosity));
  msg += ", node = ";
  msg += to_string(system_.node());
  event tmp{CAF_LOG_LEVEL_INFO,
            CAF_LOG_COMPONENT,
            CAF_PRETTY_FUN,
            __FILE__,
            __LINE__,
            std::move(msg),
            std::this_thread::get_id(),
            0,
            make_timestamp()};
  handle_event(tmp);
}
Esempio n. 6
0
void logger::init(actor_system_config& cfg) {
  CAF_IGNORE_UNUSED(cfg);
#if CAF_LOG_LEVEL >= 0
  namespace lg = defaults::logger;
  component_filter = get_or(cfg, "logger.component-filter",
                            lg::component_filter);
  // Parse the configured log level.
  auto verbosity = get_or(cfg, "logger.verbosity", lg::verbosity);
  switch (static_cast<uint64_t>(verbosity)) {
    case atom_uint("quiet"):
    case atom_uint("QUIET"):
      level_ = CAF_LOG_LEVEL_QUIET;
      break;
    case atom_uint("error"):
    case atom_uint("ERROR"):
      level_ = CAF_LOG_LEVEL_ERROR;
      break;
    case atom_uint("warning"):
    case atom_uint("WARNING"):
      level_ = CAF_LOG_LEVEL_WARNING;
      break;
    case atom_uint("info"):
    case atom_uint("INFO"):
      level_ = CAF_LOG_LEVEL_INFO;
      break;
    case atom_uint("debug"):
    case atom_uint("DEBUG"):
      level_ = CAF_LOG_LEVEL_DEBUG;
      break;
    case atom_uint("trace"):
    case atom_uint("TRACE"):
      level_ = CAF_LOG_LEVEL_TRACE;
      break;
    default: {
      // nop
    }
  }
  // Parse the format string.
  file_format_ = parse_format(get_or(cfg, "logger.file-format",
                                     lg::file_format));
  console_format_ = parse_format(get_or(cfg,"logger.console-format",
                                        lg::console_format));
  // Set flags.
  if (get_or(cfg, "logger.inline-output", false))
    set(inline_output_flag);
  auto con_atm = get_or(cfg, "logger.console", lg::console);
  if (con_atm == atom("UNCOLORED"))
    set(uncolored_console_flag);
  else if (con_atm == atom("COLORED"))
    set(colored_console_flag);
#endif
}
mapped_type runtime_settings_map::get(atom_value key) const {
  mapped_type fallback;
  return get_or(key, fallback);
}