blob: f158b81af028c3b75ba671aeab56e169c6c74df8 [file] [log] [blame]
Alexander Afanasyev216df012015-02-10 17:35:46 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyeva8d404b2016-11-05 10:07:08 -06003 * Copyright (c) 2014-2016, 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 * The University of Memphis.
Alexander Afanasyev216df012015-02-10 17:35:46 -080010 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Alexander Afanasyeva8d404b2016-11-05 10:07:08 -060024 */
Alexander Afanasyev216df012015-02-10 17:35:46 -080025
26#ifndef NFD_ANDROID_CUSTOM_LOGGER_FACTORY_HPP
27#define NFD_ANDROID_CUSTOM_LOGGER_FACTORY_HPP
28
Alexander Afanasyeva8d404b2016-11-05 10:07:08 -060029#include "core/common.hpp"
Alexander Afanasyev216df012015-02-10 17:35:46 -080030
Alexander Afanasyev54732342015-12-02 16:34:25 -080031#include "core/config-file.hpp"
32#include "core/logger.hpp"
Alexander Afanasyev216df012015-02-10 17:35:46 -080033
34namespace nfd {
35
36class LoggerFactory : noncopyable
37{
38public:
39
40 class Error : public std::runtime_error
41 {
42 public:
43 explicit
44 Error(const std::string& error)
45 : std::runtime_error(error)
46 {
47 }
48 };
49
50 static LoggerFactory&
51 getInstance();
52
53 void
54 setConfigFile(ConfigFile& config);
55
56 void
57 onConfig(const ConfigSection& section, bool isDryRun, const std::string& filename);
58
59 std::list<std::string>
60 getModules() const;
61
62 static Logger&
63 create(const std::string& moduleName);
64
65
66PUBLIC_WITH_TESTS_ELSE_PRIVATE:
67
68 // these methods are used during unit-testing
69
70 LogLevel
71 getDefaultLevel() const;
72
73 void
74 setDefaultLevel(LogLevel level);
75
76private:
77
78 LoggerFactory();
79
80 Logger&
81 createLogger(const std::string& moduleName);
82
83 LogLevel
84 parseLevel(const std::string& level);
85
86 LogLevel
87 extractLevel(const ConfigSection& item, const std::string& key);
88
89private:
90
91 typedef std::map<std::string, LogLevel> LevelMap;
92 typedef std::pair<std::string, LogLevel> NameAndLevel;
93
94 LevelMap m_levelNames;
95
96 typedef std::map<std::string, Logger> LoggerMap;
97 typedef std::pair<std::string, Logger> NameAndLogger;
98
99 LoggerMap m_loggers;
100
101 LogLevel m_defaultLevel;
102};
103
104inline LogLevel
105LoggerFactory::getDefaultLevel() const
106{
107 return m_defaultLevel;
108}
109
110} // namespace nfd
111
112#endif // NFD_ANDROID_CUSTOM_LOGGER_FACTORY_HPP