Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2014 Regents of the University of California, |
| 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology |
| 9 | * |
| 10 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 11 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 12 | * |
| 13 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 14 | * of the GNU General Public License as published by the Free Software Foundation, |
| 15 | * either version 3 of the License, or (at your option) any later version. |
| 16 | * |
| 17 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 18 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 19 | * PURPOSE. See the GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License along with |
| 22 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 23 | **/ |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 24 | |
| 25 | #ifndef NFD_CORE_LOGGER_FACTORY_HPP |
| 26 | #define NFD_CORE_LOGGER_FACTORY_HPP |
| 27 | |
| 28 | #include "common.hpp" |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame^] | 29 | #include "config-file.hpp" |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 30 | #include "logger.hpp" |
| 31 | |
| 32 | namespace nfd { |
| 33 | |
| 34 | class LoggerFactory : noncopyable |
| 35 | { |
| 36 | public: |
| 37 | |
| 38 | class Error : public std::runtime_error |
| 39 | { |
| 40 | public: |
| 41 | explicit |
| 42 | Error(const std::string& error) |
| 43 | : std::runtime_error(error) |
| 44 | { |
| 45 | } |
| 46 | }; |
| 47 | |
| 48 | static LoggerFactory& |
| 49 | getInstance(); |
| 50 | |
| 51 | void |
| 52 | setConfigFile(ConfigFile& config); |
| 53 | |
| 54 | void |
| 55 | onConfig(const ConfigSection& section, bool isDryRun, const std::string& filename); |
| 56 | |
| 57 | std::list<std::string> |
| 58 | getModules() const; |
| 59 | |
| 60 | static Logger& |
| 61 | create(const std::string& moduleName); |
| 62 | |
| 63 | |
| 64 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
| 65 | |
| 66 | // these methods are used during unit-testing |
| 67 | |
| 68 | LogLevel |
| 69 | getDefaultLevel() const; |
| 70 | |
| 71 | void |
| 72 | setDefaultLevel(LogLevel level); |
| 73 | |
| 74 | private: |
| 75 | |
| 76 | LoggerFactory(); |
| 77 | |
| 78 | Logger& |
| 79 | createLogger(const std::string& moduleName); |
| 80 | |
| 81 | LogLevel |
| 82 | parseLevel(const std::string& level); |
| 83 | |
| 84 | private: |
| 85 | |
| 86 | typedef std::map<std::string, LogLevel> LevelMap; |
| 87 | typedef std::pair<std::string, LogLevel> NameAndLevel; |
| 88 | |
| 89 | LevelMap m_levelNames; |
| 90 | |
| 91 | typedef std::map<std::string, Logger> LoggerMap; |
| 92 | typedef std::pair<std::string, Logger> NameAndLogger; |
| 93 | |
| 94 | LoggerMap m_loggers; |
| 95 | |
| 96 | LogLevel m_defaultLevel; |
| 97 | }; |
| 98 | |
| 99 | inline LogLevel |
| 100 | LoggerFactory::getDefaultLevel() const |
| 101 | { |
| 102 | return m_defaultLevel; |
| 103 | } |
| 104 | |
| 105 | } // namespace nfd |
| 106 | |
| 107 | #endif // NFD_CORE_LOGGER_FACTORY_HPP |