blob: 10a961e8c070186834532de6a64171899e6d9d6e [file] [log] [blame]
Alexander Afanasyev216df012015-02-10 17:35:46 -08001/* -*- 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 **/
24
25#ifndef NFD_ANDROID_CUSTOM_LOGGER_FACTORY_HPP
26#define NFD_ANDROID_CUSTOM_LOGGER_FACTORY_HPP
27
28#include "common.hpp"
29
Alexander Afanasyev54732342015-12-02 16:34:25 -080030#include "core/config-file.hpp"
31#include "core/logger.hpp"
Alexander Afanasyev216df012015-02-10 17:35:46 -080032
33namespace nfd {
34
35class LoggerFactory : noncopyable
36{
37public:
38
39 class Error : public std::runtime_error
40 {
41 public:
42 explicit
43 Error(const std::string& error)
44 : std::runtime_error(error)
45 {
46 }
47 };
48
49 static LoggerFactory&
50 getInstance();
51
52 void
53 setConfigFile(ConfigFile& config);
54
55 void
56 onConfig(const ConfigSection& section, bool isDryRun, const std::string& filename);
57
58 std::list<std::string>
59 getModules() const;
60
61 static Logger&
62 create(const std::string& moduleName);
63
64
65PUBLIC_WITH_TESTS_ELSE_PRIVATE:
66
67 // these methods are used during unit-testing
68
69 LogLevel
70 getDefaultLevel() const;
71
72 void
73 setDefaultLevel(LogLevel level);
74
75private:
76
77 LoggerFactory();
78
79 Logger&
80 createLogger(const std::string& moduleName);
81
82 LogLevel
83 parseLevel(const std::string& level);
84
85 LogLevel
86 extractLevel(const ConfigSection& item, const std::string& key);
87
88private:
89
90 typedef std::map<std::string, LogLevel> LevelMap;
91 typedef std::pair<std::string, LogLevel> NameAndLevel;
92
93 LevelMap m_levelNames;
94
95 typedef std::map<std::string, Logger> LoggerMap;
96 typedef std::pair<std::string, Logger> NameAndLogger;
97
98 LoggerMap m_loggers;
99
100 LogLevel m_defaultLevel;
101};
102
103inline LogLevel
104LoggerFactory::getDefaultLevel() const
105{
106 return m_defaultLevel;
107}
108
109} // namespace nfd
110
111#endif // NFD_ANDROID_CUSTOM_LOGGER_FACTORY_HPP