forked from kinnalru/soft-pkcs11
-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.cpp
57 lines (41 loc) · 741 Bytes
/
log.cpp
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
#include <stdarg.h>
#include "tools.h"
#include "log.h"
static logger_t* logger = 0;
static int tab = 0;
logger_t& logger_t::instance()
{
if (!logger) {
logger = new logger_t();
}
return *logger;
}
logger_t& logger_t::operator()(const std::string& msg)
{
print_tab();
st_logf(msg.c_str());
return *this;
}
logger_t& logger_t::operator()(const char* fmt, ...)
{
print_tab();
va_list ap;
va_start(ap, fmt);
st_logf(fmt, ap);
va_end(ap);
return *this;
}
void logger_t::print_tab()
{
if (tab > 0) {
st_logf(std::string(tab * 3, ' ').c_str());
}
}
logger_t::scopped_t::scopped_t()
{
++tab;
}
logger_t::scopped_t::~scopped_t()
{
--tab;
}