Helios++
Helios software for LiDAR simulations
logger_factory.hpp
1 #pragma once
2 
3 #include <logging_common.hpp>
4 #include <logging_creation.hpp>
5 
10 protected:
11  // *** ATTRIBUTES *** //
12  // ******************** //
16  std::unordered_map<std::string, logger_creator> creators;
17 public:
18  // *** CONSTRUCTION / DESTRUCTION *** //
19  // ************************************ //
24  creators.emplace(
25  "",
26  [](const logging_config_t& config)->logger*{
27  return new logger(config);
28  }
29  );
30  creators.emplace(
31  "std_out",
32  [](const logging_config_t& config)->logger*{
33  return new std_out_logger(config);
34  }
35  );
36  creators.emplace(
37  "file",
38  [](const logging_config_t& config)->logger*{
39  return new file_logger(config);
40  }
41  );
42  creators.emplace(
43  "full",
44  [](const logging_config_t& config)->logger*{
45  return new full_logger(config);
46  }
47  );
48  }
49 
50  // *** M E T H O D S *** //
51  // *********************** //
57  logger* produce(const logging_config_t& config) const {
58  //grab the type
59  auto type = config.find("type");
60  if(type == config.end()){
61  throw std::runtime_error(
62  "Logging factory configuration requires a type of logger"
63  );
64  }
65  //grab the logger
66  auto found = creators.find(type->second);
67  if(found != creators.end()) return found->second(config);
68  //couldn't get a logger
69  throw std::runtime_error(
70  "Couldn't produce logger for type: " + type->second
71  );
72  }
73 };
logger * produce(const logging_config_t &config) const
Produce a logger.
Definition: logger_factory.hpp:57
Class representing a logger capable of writing to standard out stream.
Definition: std_out_logger.hpp:7
Logger factory class can be used to build loggers.
Definition: logger_factory.hpp:9
std::unordered_map< std::string, logger_creator > creators
Logger creation map which works with function pointers.
Definition: logger_factory.hpp:16
Class providing the base for any logger.
Definition: logger.hpp:8
logger_factory()
Logger factory constructor.
Definition: logger_factory.hpp:23
Class representing a logger capable of writing to files and, at the same time, to standard out...
Definition: full_logger.hpp:7
Class representing a logger capable of writing to files.
Definition: file_logger.hpp:8