OGS
Logging.cpp
Go to the documentation of this file.
1 
12 #include "Logging.h"
13 
14 #include <spdlog/sinks/stdout_color_sinks.h>
15 #include <spdlog/spdlog.h>
16 
17 #include <map>
18 
19 #ifdef USE_PETSC
20 #include <mpi.h>
21 #include <petscsys.h>
22 #endif
23 
24 #include "Error.h"
25 
26 namespace BaseLib
27 {
28 #ifdef USE_PETSC
29 std::shared_ptr<spdlog::logger> console = spdlog::stdout_color_mt("ogs");
30 #else // USE_PETSC
31 std::shared_ptr<spdlog::logger> console = spdlog::stdout_color_st("ogs");
32 #endif // USE_PETSC
33 
34 void setConsoleLogLevel(std::string const& level_string)
35 {
36  using namespace spdlog::level;
37  std::map<std::string, level_enum> string_to_log_level = {
38  {"none", off}, {"critical", critical}, {"error", err}, {"warn", warn},
39  {"info", info}, {"debug", debug}, {"all", trace}};
40 
41  auto const level = string_to_log_level.find(level_string);
42  if (level == string_to_log_level.end())
43  {
44  ERR("'{:s}' is not a valid log level!", level_string);
45  OGS_FATAL("Wrong log level string.");
46  }
47  console->set_level(level->second);
48  spdlog::set_default_logger(console);
49 }
50 } // namespace BaseLib
#define OGS_FATAL(...)
Definition: Error.h:26
void ERR(char const *fmt, Args const &... args)
Definition: Logging.h:42
std::shared_ptr< spdlog::logger > console
Definition: Logging.cpp:29
void setConsoleLogLevel(std::string const &level_string)
Definition: Logging.cpp:34