Molecular Dynamics Simulation  1.0
Public Types | Static Public Member Functions | Static Public Attributes | List of all members
Logger Class Reference

Class as wrapper and initializer for a globally usable logger. More...

#include <Logger.h>

Collaboration diagram for Logger:
Collaboration graph

Public Types

enum class  LogType { FILE , STD }
 Enum for the type of logger. More...
 

Static Public Member Functions

static std::shared_ptr< spdlog::logger > init_logger (LogType log_type=LogType::STD)
 Initializes the logger. More...
 
static void update_level (std::string &log_level)
 Sets the log level of the logger. More...
 

Static Public Attributes

static std::shared_ptr< spdlog::logger > logger = init_logger()
 Publically accessible shared pointer to the logger. More...
 

Detailed Description

Class as wrapper and initializer for a globally usable logger.

Definition at line 18 of file Logger.h.

Member Enumeration Documentation

◆ LogType

enum Logger::LogType
strong

Enum for the type of logger.

Enumerator
FILE 
STD 

Definition at line 23 of file Logger.h.

23 { FILE, STD };

Member Function Documentation

◆ init_logger()

std::shared_ptr< spdlog::logger > Logger::init_logger ( LogType  log_type = LogType::STD)
static

Initializes the logger.

Definition at line 23 of file Logger.cpp.

23  {
24  auto standard_out = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
25  standard_out->set_color(spdlog::level::critical, standard_out->dark);
26  standard_out->set_color(spdlog::level::err, standard_out->red);
27  standard_out->set_color(spdlog::level::warn, standard_out->yellow);
28  standard_out->set_color(spdlog::level::info, standard_out->green);
29  standard_out->set_color(spdlog::level::debug, standard_out->blue);
30  standard_out->set_color(spdlog::level::trace, standard_out->magenta);
31 
32  spdlog::init_thread_pool(8192, 1);
33  std::shared_ptr<spdlog::logger> new_logger;
34  if (log_type == LogType::FILE) {
35  createDirectory("logs");
36  new_logger = spdlog::rotating_logger_st("file_logger", "logs/log", 1048576 * 5, 3);
37  } else {
38  new_logger =
39  std::make_shared<spdlog::async_logger>("std_logger", standard_out, spdlog::thread_pool(), spdlog::async_overflow_policy::block);
40  }
41 
42  new_logger->set_level(spdlog::level::off);
43  new_logger->set_pattern("[%H:%M:%S] %^[%l]%$ %v");
44 
45  return new_logger;
46 }
void createDirectory(const std::string &dir_name)
Definition: Logger.cpp:12

◆ update_level()

void Logger::update_level ( std::string &  log_level)
static

Sets the log level of the logger.

Parameters
log_levelThe log level to set

Definition at line 48 of file Logger.cpp.

48  {
49  if (log_level == "trace") {
50  Logger::logger->set_level(spdlog::level::trace);
51  } else if (log_level == "debug") {
52  Logger::logger->set_level(spdlog::level::debug);
53  } else if (log_level == "info") {
54  Logger::logger->set_level(spdlog::level::info);
55  } else if (log_level == "warning") {
56  Logger::logger->set_level(spdlog::level::warn);
57  } else if (log_level == "error") {
58  Logger::logger->set_level(spdlog::level::err);
59  } else if (log_level == "critical") {
60  logger->set_level(spdlog::level::critical);
61  } else if (log_level == "off") {
62  Logger::logger->set_level(spdlog::level::off);
63  } else {
64  std::cout << "Error: Invalid log level given." << std::endl;
65  throw std::invalid_argument("Invalid log level given.");
66  }
67 }
static std::shared_ptr< spdlog::logger > logger
Publically accessible shared pointer to the logger.
Definition: Logger.h:35

Member Data Documentation

◆ logger

std::shared_ptr< spdlog::logger > Logger::logger = init_logger()
static

Publically accessible shared pointer to the logger.

Returns
Logger

Definition at line 35 of file Logger.h.


The documentation for this class was generated from the following files: