Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame^] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (C) 2014 Named Data Networking Project |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | #ifndef NFD_CORE_LOGGER_FACTORY_HPP |
| 8 | #define NFD_CORE_LOGGER_FACTORY_HPP |
| 9 | |
| 10 | #include "common.hpp" |
| 11 | #include "mgmt/config-file.hpp" |
| 12 | #include "logger.hpp" |
| 13 | |
| 14 | namespace nfd { |
| 15 | |
| 16 | class LoggerFactory : noncopyable |
| 17 | { |
| 18 | public: |
| 19 | |
| 20 | class Error : public std::runtime_error |
| 21 | { |
| 22 | public: |
| 23 | explicit |
| 24 | Error(const std::string& error) |
| 25 | : std::runtime_error(error) |
| 26 | { |
| 27 | } |
| 28 | }; |
| 29 | |
| 30 | static LoggerFactory& |
| 31 | getInstance(); |
| 32 | |
| 33 | void |
| 34 | setConfigFile(ConfigFile& config); |
| 35 | |
| 36 | void |
| 37 | onConfig(const ConfigSection& section, bool isDryRun, const std::string& filename); |
| 38 | |
| 39 | std::list<std::string> |
| 40 | getModules() const; |
| 41 | |
| 42 | static Logger& |
| 43 | create(const std::string& moduleName); |
| 44 | |
| 45 | |
| 46 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
| 47 | |
| 48 | // these methods are used during unit-testing |
| 49 | |
| 50 | LogLevel |
| 51 | getDefaultLevel() const; |
| 52 | |
| 53 | void |
| 54 | setDefaultLevel(LogLevel level); |
| 55 | |
| 56 | private: |
| 57 | |
| 58 | LoggerFactory(); |
| 59 | |
| 60 | Logger& |
| 61 | createLogger(const std::string& moduleName); |
| 62 | |
| 63 | LogLevel |
| 64 | parseLevel(const std::string& level); |
| 65 | |
| 66 | private: |
| 67 | |
| 68 | typedef std::map<std::string, LogLevel> LevelMap; |
| 69 | typedef std::pair<std::string, LogLevel> NameAndLevel; |
| 70 | |
| 71 | LevelMap m_levelNames; |
| 72 | |
| 73 | typedef std::map<std::string, Logger> LoggerMap; |
| 74 | typedef std::pair<std::string, Logger> NameAndLogger; |
| 75 | |
| 76 | LoggerMap m_loggers; |
| 77 | |
| 78 | LogLevel m_defaultLevel; |
| 79 | }; |
| 80 | |
| 81 | inline LogLevel |
| 82 | LoggerFactory::getDefaultLevel() const |
| 83 | { |
| 84 | return m_defaultLevel; |
| 85 | } |
| 86 | |
| 87 | } // namespace nfd |
| 88 | |
| 89 | #endif // NFD_CORE_LOGGER_FACTORY_HPP |