-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathts_logger.h
55 lines (45 loc) · 1.13 KB
/
ts_logger.h
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
#ifndef TS_LOGGER_H
#define TS_LOGGER_H
#include <bits/stdc++.h>
namespace utilities
{
enum class log_level: int
{
off = 0,
error,
warning,
info,
default_level = info,
debug,
_last
};
class logger
{
public:
static logger& get_instance(); // for singleton class
logger(const logger&) = delete;
logger& operator=(const logger&) = delete;
logger(logger&&) = delete;
logger& operator=(logger&&) = delete;
void set_level(log_level level);
log_level get_level() const;
void shutdown();
template<typename... Args>
void write(log_level level, Args&&... args)
{
if (level <= get_level())
{
std::ostringstream oss;
(oss << ... << std::forward<Args>(args));
write_impl(level, oss.str());
}
}
private:
logger();
~logger();
void write_impl(log_level level, const std::string& msg);
struct impl;
std::unique_ptr<impl> pimpl;
};
}
#endif // TS_LOGGER_H