-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefault.cpp
More file actions
166 lines (137 loc) · 3.55 KB
/
default.cpp
File metadata and controls
166 lines (137 loc) · 3.55 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#include "default.h"
#include "logger.h"
#include "message.h"
#include "acore/logging/sinks/file_sink.h"
#include "acore/std/types.h"
#ifndef __QNX__
#include <unordered_map>
namespace acore
{
namespace logging
{
static std::unordered_map<std::string, LoggerPtr> m_registry;
#else
#include "acore/logging/formatters/path_formatter.h"
#include "acore/logging/logger.h"
#include "acore/std/map.hpp"
static map<string, LoggerPtr> m_registry;
#endif
static LoggerPtr m_defaultLogger;
#ifndef __QNX__
void debug(const std::string &format_str, acore::format::ArgList args)
{
if (!m_defaultLogger)
{
throw std::runtime_error("Default logger wasn't set");
}
m_defaultLogger->debug(format_str, args);
}
void info(const std::string &format_str, acore::format::ArgList args)
{
if (!m_defaultLogger)
{
throw std::runtime_error("Default logger wasn't set");
}
m_defaultLogger->info(format_str, args);
}
void warning(const std::string &format_str, acore::format::ArgList args)
{
if (!m_defaultLogger)
{
throw std::runtime_error("Default logger wasn't set");
}
m_defaultLogger->warning(format_str, args);
}
void error(const std::string &format_str, acore::format::ArgList args)
{
if (!m_defaultLogger)
{
throw std::runtime_error("Default logger wasn't set");
}
m_defaultLogger->error(format_str, args);
}
void critical(const std::string &format_str, acore::format::ArgList args)
{
if (!m_defaultLogger)
{
throw std::runtime_error("Default logger wasn't set");
}
m_defaultLogger->critical(format_str, args);
}
void append(const std::string &path,
const std::string &format_str,
acore::format::ArgList args)
{
sinks::FileSink fsink(path);
fsink.log(acore::format::format(format_str.c_str(), args),
level_t::Undefined);
}
#else
void debug(const std::string &message)
{
m_defaultLogger->debug(message);
}
void info(const std::string &message)
{
m_defaultLogger->info(message);
}
void warning(const std::string &message)
{
m_defaultLogger->warning(message);
}
void error(const std::string &message)
{
m_defaultLogger->error(message);
}
void critical(const std::string &message)
{
m_defaultLogger->critical(message);
}
void append(const std::string &path, const std::string &message)
{
FileSink fsink(path);
fsink.log(message, level_t::Undefined);
}
#endif
void set_default(LoggerPtr lptr)
{
#ifndef __QNX__
std::pair<std::unordered_map<std::string, LoggerPtr>::iterator, bool>
pair = m_registry.insert({ lptr->get_name(), lptr });
// pair.first - iterator, iterator->second - LoggerPtr
m_defaultLogger = pair.first->second;
#else
m_registry[lptr->get_name()] = lptr;
m_defaultLogger = lptr;
#endif
}
void register_logger(LoggerPtr lptr)
{
#ifdef __QNX__
m_registry[lptr->get_name()] = lptr;
#else
m_registry.insert({ lptr->get_name(), lptr });
#endif
}
LoggerPtr get(const std::string &name)
{
return m_registry.at(name);
}
LoggerPtr get_default()
{
return m_defaultLogger;
}
#ifndef __QNX__
void drop(const std::string &name)
{
m_registry.erase(name);
}
#endif
void drop_all()
{
m_registry.clear();
}
#ifndef __QNX__
} // namespace logging
} // namespace acore
#endif