Helios++
Helios software for LiDAR simulations
std_out_logger.hpp
1 #pragma once
2 
3 //logger that writes to standard out
7 class std_out_logger : public logger {
8 protected:
9  // *** ATTRIBUTES *** //
10  // ******************** //
16  const std::unordered_map<log_level, std::string, enum_hasher> levels;
17 
18 public:
19  // *** CONSTRUCTION / DESTRUCTION *** //
20  // ************************************ //
21  std_out_logger() = delete;
27  std_out_logger(const logging_config_t& config):
28  logger(config),
29  levels(config.find("color") != config.end() ? colored : uncolored)
30  {}
31 
32  // *** M E T H O D S *** //
33  // *********************** //
37  virtual void log(const std::string& message, const log_level level) {
38  if(level < LOG_LEVEL_CUTOFF) return;
39  std::string output;
40  output.reserve(message.length() + 64);
41  //output.append(timestamp());
42  //output.append(levels.find(level)->second);
43  output.append(message);
44  output.push_back('\n');
45  log(output);
46  }
50  virtual void log(const std::string& message) {
51  //cout is thread safe, to avoid multiple threads interleaving on one line
52  //though, we make sure to only call the << operator once on std::cout
53  //otherwise the << operators from different threads could interleave
54  //obviously we dont care if flushes interleave
55  std::cout << message;
56  std::cout.flush();
57  }
58 };
virtual void log(const std::string &message)
Definition: std_out_logger.hpp:50
std_out_logger(const logging_config_t &config)
Standard out logger constructor.
Definition: std_out_logger.hpp:27
Class representing a logger capable of writing to standard out stream.
Definition: std_out_logger.hpp:7
const std::unordered_map< log_level, std::string, enum_hasher > levels
Map of logging levels.
Definition: std_out_logger.hpp:16
virtual void log(const std::string &message, const log_level level)
Definition: std_out_logger.hpp:37
Class providing the base for any logger.
Definition: logger.hpp:8