xs/log.xs

filter: Statementstmt 100% 29 / 29 Branchbran 72.7% 16 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 88.2% 45 / 51 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/punk/punk_mpstream.h ↑ Summary xs/markdown.xs »
1 MODULE = Punk PACKAGE = Punk::Logger
2  
3 PROTOTYPES: DISABLE
4  
5 # Build the sprintf coderef once, at load, so it never runs eval_pv mid-log
6 # (which would disturb the argument stack of the call in progress).
7 BOOT:
8 354 pl_define_fmt(aTHX);
9  
10 # The level-based logger, in C (punk_log.h). debug/info/warn/error/fatal (and a
11 # generic log($level, ...)) format a message - one arg as-is, several via
12 # sprintf - and emit it. lib/Punk/Logger.pm is documentation.
13 SV *
14 debug(self, ...)
15 SV *self
16 ALIAS:
17 info = 1
18 warn = 2
19 error = 3
20 fatal = 4
21 CODE:
22 {
23 130 int argc = items - 1, i;
24 SV **argv;
25 130 ▶ Newx(argv, argc > 0 ? argc : 1, SV *); /* # uncoverable condition right count:1 class:ignore_covered_err */
Branch: 1 branch
BranchTrueFalseTotal
Newx(argv, argc > 0 ? argc : 1, SV *); /* # uncoverable condition right count:1 class:ignore_covered_err */ 130 0 130
26 265 ▶ for (i = 0; i < argc; i++) argv[i] = ST(i + 1);
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < argc; i++) argv[i] = ST(i + 1); 135 130 265
27 130 pl_method(aTHX_ self, (int)ix, argv, argc);
28 129 Safefree(argv);
29 129 RETVAL = newSVsv(self);
30 }
31 OUTPUT:
32 RETVAL
33  
34 # log($level => $message, @args): the level-first form.
35 SV *
36 log(self, level, ...)
37 SV *self
38 SV *level
39 CODE:
40 {
41 2 int lvl = pl_level_num(aTHX_ level);
42 2 int argc = items - 2, i;
43 SV **argv;
44 2 ▶ Newx(argv, argc > 0 ? argc : 1, SV *); /* # uncoverable condition right count:1 class:ignore_covered_err */
Branch: 1 branch
BranchTrueFalseTotal
Newx(argv, argc > 0 ? argc : 1, SV *); /* # uncoverable condition right count:1 class:ignore_covered_err */ 2 0 2
45 5 ▶ for (i = 0; i < argc; i++) argv[i] = ST(i + 2);
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < argc; i++) argv[i] = ST(i + 2); 3 2 5
46 2 pl_method(aTHX_ self, lvl, argv, argc);
47 2 Safefree(argv);
48 2 RETVAL = newSVsv(self);
49 }
50 OUTPUT:
51 RETVAL
52  
53 MODULE = Punk PACKAGE = Punk::App
54  
55 # $app->log: the application logger (no request context), cached on the app.
56 SV *
57 log(self)
58 SV *self
59 CODE:
60 {
61 3 HV *h = app_hv(aTHX_ self);
62 3 SV **cached = hv_fetchs(h, "logger", 0);
63 3 ▶ # uncoverable condition right count:2 class:ignore_covered_err
Branch: 3 branches
BranchTrueFalseTotal
# uncoverable condition right count:2 class:ignore_covered_err 1 2 3
# uncoverable condition right count:2 class:ignore_covered_err 1 0 1
# uncoverable condition right count:2 class:ignore_covered_err 1 0 1
64 # uncoverable condition right count:3 class:ignore_covered_err
65 2 if (cached && *cached && SvROK(*cached)) RETVAL = newSVsv(*cached);
66 2 else {
67 2 SV *lg = pl_make_logger(aTHX_ self, NULL);
68 (void)hv_stores(h, "logger", newSVsv(lg));
69 RETVAL = lg;
70 }
71 }
72 OUTPUT:
73 RETVAL
74  
75 MODULE = Punk PACKAGE = Punk::Context
76  
77 # $c->log: the request logger (adds method/path), cached in the stash.
78 SV *
79 log(self)
80 SV *self
81 CODE:
82 {
83 97 AV *av = pcx_av(aTHX_ self);
84 97 SV *st = pcx_get(aTHX_ av, PCX_STASH);
85 HV *stash;
86 SV **cached;
87 97 ▶ if (!st) { st = newRV_noinc((SV *)newHV()); (void)av_store(av, PCX_STASH, st); }
Branch: 1 branch
BranchTrueFalseTotal
if (!st) { st = newRV_noinc((SV *)newHV()); (void)av_store(av, PCX_STASH, st); } 61 36 97
88 97 stash = (HV *)SvRV(st);
89 97 cached = hv_fetchs(stash, "punk.logger", 0);
90 97 ▶ # uncoverable condition right count:2 class:ignore_covered_err
Branch: 3 branches
BranchTrueFalseTotal
# uncoverable condition right count:2 class:ignore_covered_err 36 61 97
# uncoverable condition right count:2 class:ignore_covered_err 36 0 36
# uncoverable condition right count:2 class:ignore_covered_err 36 0 36
91 # uncoverable condition right count:3 class:ignore_covered_err
92 61 if (cached && *cached && SvROK(*cached)) RETVAL = newSVsv(*cached);
93 61 else {
94 61 SV *lg = pl_make_logger(aTHX_ pcx_get(aTHX_ av, PCX_APP), self);
95 (void)hv_stores(stash, "punk.logger", newSVsv(lg));
96 RETVAL = lg;
97 }
98 }
99 OUTPUT:
100 RETVAL
« include/punk/punk_mpstream.h ↑ Summary xs/markdown.xs »