forked from hyperledger-iroha/iroha-dco
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger_manager.hpp
65 lines (51 loc) · 1.92 KB
/
logger_manager.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
* Copyright Soramitsu Co., Ltd. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef IROHA_SPDLOG_LOGGER_MANAGER_HPP
#define IROHA_SPDLOG_LOGGER_MANAGER_HPP
#include "logger/logger_manager_fwd.hpp"
#include <memory>
#include <mutex>
#include <string>
#include <unordered_map>
#include <boost/optional.hpp>
#include "logger/logger_spdlog.hpp"
namespace logger {
/**
* A node of logger managers tree. It stores the configuration needed to
* create a logger corresponding to this node and its children. Thread safe.
*/
class LoggerManagerTree {
public:
explicit LoggerManagerTree(ConstLoggerConfigPtr config);
explicit LoggerManagerTree(LoggerConfig config);
/**
* Register a child configuration. The new child's configuration parameters
* are taken from the parent optionally overrided by the arguments. Thread
* safe.
*
* @param tag - the child's tag, without any parents' prefixes
* @param log_level - override the log level for the new child
* @param patterns - override the patterns
*/
LoggerManagerTreePtr registerChild(std::string tag,
boost::optional<LogLevel> log_level,
boost::optional<LogPatterns> patterns);
/// Get this node's logger. Thread safe.
LoggerPtr getLogger();
/// Get non-const child node by tag, if present. Thread safe.
LoggerManagerTreePtr getChild(const std::string &tag);
private:
LoggerManagerTree(std::string full_tag,
std::string node_tag,
ConstLoggerConfigPtr config);
const std::string node_tag_;
const std::string full_tag_;
const ConstLoggerConfigPtr config_;
std::shared_ptr<Logger> logger_;
std::unordered_map<std::string, LoggerManagerTreePtr> children_;
std::mutex children_mutex_;
};
} // namespace logger
#endif // IROHA_SPDLOG_LOGGER_MANAGER_HPP