示例#1
0
void wex::log::init(int argc, char** argv)
{
  // Load elp configuration from file.
  const path elp(config().dir(), "conf.elp");

  if (elp.file_exists())
  {
    el::Loggers::reconfigureAllLoggers(el::Configurations(elp.data().string()));
  }

  // We need to convert argc and argv, as elp expects = sign between values.
  // The logging-flags are handled by syncped.
  bool error = false;
  std::vector<const char*> v;
  const std::vector <std::pair<
    std::string, std::string>> supported {
      {"-m", "-vmodule"},
      {"-D", "--default-log-file"},
      {"-L", "--loggingflags"},
      {"--logfile", "--default-log-file"},
      {"--logflags", "--loggingflags"},
      {"--x", "--v"}, // for testing with verbosity
      {"--v", "--v"}};

  for (int i = 0; i < argc; i++)
  {
    bool found = false;

    for (const auto& s : supported)
    {
      if (strcmp(argv[i], s.first.c_str()) == 0)
      {
        found = true;

        if (i + 1 < argc)
        {
	        const std::string option(argv[i + 1]);
  	      v.push_back(std::string(s.second + "=" + option).c_str());
        }
        else
        {
          error = true;
        }
      }
    }

    if (!found)
    {
      v.push_back(argv[i]);
    }
  }

  START_EASYLOGGINGPP(v.size(), (const char**)&v[0]);

  verbose(1) << "verbosity:" << (int)el::Loggers::verboseLevel()
    << "config:" << elp.data().string();
  
  if (error)
  {
    log("option value missing");
  }
}