line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
MODULE = Panda::Lib PACKAGE = Panda::Lib::Logger |
2
|
|
|
|
|
|
|
PROTOTYPES: DISABLE |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
BOOT { |
5
|
11
|
50
|
|
|
|
|
xs::register_package(aTHX_ "Panda::Lib::Logger", "Panda::Lib"); |
6
|
11
|
50
|
|
|
|
|
xs::inherit_package(aTHX_ "Panda::Lib::Logger", "Panda::Lib"); |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
constant_t clist_main[] = { |
9
|
|
|
|
|
|
|
{"LOG_EMERGENCY", Level::EMERGENCY, NULL}, |
10
|
|
|
|
|
|
|
{"LOG_CRITICAL", Level::CRITICAL, NULL}, |
11
|
|
|
|
|
|
|
{"LOG_WARNING", Level::WARNING, NULL}, |
12
|
|
|
|
|
|
|
{"LOG_INFO", Level::INFO, NULL}, |
13
|
|
|
|
|
|
|
{"LOG_VERBOSE", Level::VERBOSE, NULL}, |
14
|
|
|
|
|
|
|
{"LOG_DEBUG", Level::DEBUG, NULL}, |
15
|
|
|
|
|
|
|
{NULL, 0, NULL} |
16
|
11
|
|
|
|
|
|
}; |
17
|
11
|
50
|
|
|
|
|
HV* plib_stash = gv_stashpvs("Panda::Lib::Logger", GV_ADD); |
18
|
11
|
50
|
|
|
|
|
create_constants(aTHX_ plib_stash, clist_main); |
19
|
|
|
|
|
|
|
|
20
|
11
|
50
|
|
|
|
|
register_export(aTHX_ plib_stash, "set_log_level"); |
21
|
11
|
50
|
|
|
|
|
register_export(aTHX_ plib_stash, "set_native_logger"); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
void set_log_level(int level) { |
25
|
0
|
|
|
|
|
|
panda::Log::set_max_level((Level)level); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
void set_native_logger(CV* cb) { |
29
|
0
|
|
|
|
|
|
xs::SvIntrPtr cb_ptr(cb); |
30
|
0
|
|
|
|
|
|
struct CatchLogger : panda::logger::ILogger { |
31
|
|
|
|
|
|
|
xs::SvIntrPtr cb; |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
virtual void log(panda::logger::Level l, panda::logger::CodePoint cp, const std::string& s) override { |
34
|
|
|
|
|
|
|
dTHX; |
35
|
0
|
0
|
|
|
|
|
auto cp_str = cp.to_string(); |
36
|
0
|
0
|
|
|
|
|
SV* args[] = {newSViv(l), newSVpv(cp_str.c_str(), cp_str.size()), newSVpv(s.c_str(), s.size())}; |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
37
|
0
|
0
|
|
|
|
|
xs::call_sub_void(aTHX_ cb.get(), args, 3); |
38
|
0
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
}; |
40
|
0
|
0
|
|
|
|
|
auto log = new CatchLogger; |
41
|
0
|
0
|
|
|
|
|
log->cb = cb_ptr; |
42
|
0
|
0
|
|
|
|
|
panda::Log::logger().reset(log); |
43
|
|
|
|
|
|
|
} |