Lugdunum  0.1.0
Logger.cpp
Go to the documentation of this file.
3 
4 namespace lug {
5 namespace System {
6 namespace Logger {
7 
8 #define LUG_LOG_ENUM(CHANNEL) case Level::CHANNEL: return os << #CHANNEL;
9 
10 std::ostream& operator<<(std::ostream& os, Level level) {
11  switch (level) {
13  }
14  return os << "Unknown";
15 }
16 
17 #undef LUG_LOG_ENUM
18 
19 Logger::Logger(const std::string& loggerName) : _name(loggerName) {}
20 
21 void Logger::addHandler(Handler* handler) {
22  _handlers.insert(handler);
23 }
24 
25 void Logger::addHandler(const std::string& name) {
27 }
28 
29 void Logger::defaultErrHandler(const std::string& msg) {
30  log(Level::Fatal, "Exception in logger {}: {}", _name, msg);
31 }
32 
33 void Logger::defaultErrHandler(const std::exception& ex) {
34  defaultErrHandler(ex.what());
35 }
36 
37 const std::string& Logger::getName() const {
38  return _name;
39 }
40 
41 void Logger::handle(priv::Message& msg) {
42  for (auto& handler : _handlers) {
43  if (handler->shouldLog(msg.level)) {
44  handler->format(msg);
45  handler->handle(msg);
46  }
47  }
48 }
49 
50 void Logger::flush() {
51  for (auto& handler : _handlers) {
52  handler->flush();
53  }
54 }
55 
57  static Logger logger("internal");
58 
59  return logger;
60 }
61 
62 } // namespace Logger
63 } // namespace System
64 } // namespace lug
std::ostream & operator<<(std::ostream &os, Level level)
Definition: Logger.cpp:10
static Handler * getHandler(const std::string &handlerName)
void addHandler(Handler *handler)
Definition: Logger.cpp:21
std::set< Handler * > _handlers
Definition: Logger.hpp:68
void defaultErrHandler(const std::exception &ex)
Definition: Logger.cpp:33
void log(Level lvl, const T &msg)
#define LUG_LOG_LEVELS(PROCESS)
Definition: Common.hpp:21
void defaultErrHandler(const std::string &msg)
Definition: Logger.cpp:29
const std::string & getName() const
Definition: Logger.cpp:37
#define LUG_LOG_ENUM(CHANNEL)
Definition: Logger.cpp:8
static Logger & getInternalLogger()
Definition: Logger.cpp:56
void handle(priv::Message &msg)
Definition: Logger.cpp:41
const std::string _name
Definition: Logger.hpp:67