line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#include "xlog.h" |
2
|
|
|
|
|
|
|
#include |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
using namespace xs; |
5
|
|
|
|
|
|
|
using namespace panda; |
6
|
|
|
|
|
|
|
using namespace panda::log; |
7
|
|
|
|
|
|
|
|
8
|
64
|
50
|
|
|
|
|
struct PerlSubLogger : ILogger { |
9
|
|
|
|
|
|
|
using fn_t = function; |
10
|
|
|
|
|
|
|
fn_t fn; |
11
|
|
|
|
|
|
|
|
12
|
16
|
50
|
|
|
|
|
PerlSubLogger (const Sub& sub) : fn(xs::in(sub)) {} |
13
|
|
|
|
|
|
|
|
14
|
19
|
|
|
|
|
|
void log (const string& msg, const Info& info) override { |
15
|
19
|
50
|
|
|
|
|
if (!is_perl_thread()) throw std::logic_error("can't call pure-perl logging callback: log() called from perl-foreign thread"); |
|
|
0
|
|
|
|
|
|
16
|
19
|
|
|
|
|
|
fn(msg, info.level); |
17
|
19
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
}; |
19
|
|
|
|
|
|
|
|
20
|
12
|
50
|
|
|
|
|
struct PerlSubFormatter : IFormatter { |
21
|
|
|
|
|
|
|
using fn_t = function; |
22
|
|
|
|
|
|
|
fn_t fn; |
23
|
|
|
|
|
|
|
|
24
|
3
|
50
|
|
|
|
|
PerlSubFormatter (const Sub& sub) : fn(xs::in(sub)) {} |
25
|
|
|
|
|
|
|
|
26
|
7
|
|
|
|
|
|
string format (std::string& msg, const Info& info) const override { |
27
|
7
|
50
|
|
|
|
|
if (!is_perl_thread()) throw std::logic_error("can't call pure-perl formatting callback: log() called from perl-foreign thread"); |
|
|
0
|
|
|
|
|
|
28
|
7
|
|
|
|
|
|
return fn(msg, info.level, info.module->name(), info.file, info.line, info.func); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
}; |
31
|
|
|
|
|
|
|
|
32
|
8
|
|
|
|
|
|
static bool _init () { |
33
|
32
|
50
|
|
|
|
|
xs::at_perl_destroy([]{ |
34
|
|
|
|
|
|
|
// remove all perl loggers and formatters from C++ modules as they are no longer available |
35
|
16
|
50
|
|
|
|
|
auto modules = get_modules(); |
36
|
22
|
100
|
|
|
|
|
for (auto module : modules) { |
37
|
14
|
50
|
|
|
|
|
if (dyn_cast(module->get_logger().get())) module->set_logger(nullptr); |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
38
|
14
|
50
|
|
|
|
|
if (dyn_cast(module->get_formatter().get())) module->set_formatter(nullptr); |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
39
|
|
|
|
|
|
|
} |
40
|
24
|
50
|
|
|
|
|
}); |
41
|
8
|
|
|
|
|
|
return true; |
42
|
|
|
|
|
|
|
} |
43
|
8
|
|
|
|
|
|
static bool __init = _init(); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
namespace xs { |
46
|
|
|
|
|
|
|
|
47
|
67
|
|
|
|
|
|
ILoggerSP Typemap::in (Sv sv) { |
48
|
67
|
100
|
|
|
|
|
if (sv.is_sub_ref()) return new PerlSubLogger(sv); |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
49
|
67
|
|
|
|
|
|
return xs::in(sv); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
58
|
|
|
|
|
|
IFormatterSP Typemap::in (Sv sv) { |
53
|
58
|
100
|
|
|
|
|
if (sv.is_sub_ref()) return new PerlSubFormatter(sv); |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
54
|
55
|
100
|
|
|
|
|
if (sv.is_string()) return new PatternFormatter(xs::in(sv)); |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
55
|
58
|
|
|
|
|
|
return xs::in(sv); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
32
|
50
|
|
|
|
|
} |
|
|
50
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|