Log.xs

filter: Statementstmt 94.2% 33 / 35 Branchbran 56.2% 18 / 32 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 76.1% 51 / 67 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/Log.c ↑ Summary
1 /***************************************************************************************
2 * Build MD5 : Z2kKlVGmp8wl2Wxaqiw2Kw
3 * Build Time : 2026-09-14 02:16:18
4 * Version : 6.090001
5 * Author : H.Q.Wang
6 ****************************************************************************************/
7 #include "EXTERN.h"
8 #include "perl.h"
9 #include "XSUB.h"
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <stdarg.h>
13 #include "include/Log.h"
14 #include "include/Log.c"
15  
16 1 static LogOptions* hv_to_LogOptions(HV* hv) {
17 1 LogOptions* opt = (LogOptions*)malloc(sizeof(LogOptions));
18 1 ▶ if (!opt) return NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (!opt) return NULL; 0 1 1
19 1 memset(opt, 0, sizeof(LogOptions));
20  
21 SV** val;
22 1 ▶ if ((val = hv_fetch(hv, "level", 5, 0))) opt->level = (LogLevel)SvIV(*val);
Branch: 1 branch
BranchTrueFalseTotal
if ((val = hv_fetch(hv, "level", 5, 0))) opt->level = (LogLevel)SvIV(*val); 1 0 1
23 1 ▶ if ((val = hv_fetch(hv, "mode", 4, 0))) opt->mode = (LogMode)SvIV(*val);
Branch: 1 branch
BranchTrueFalseTotal
if ((val = hv_fetch(hv, "mode", 4, 0))) opt->mode = (LogMode)SvIV(*val); 0 1 1
24 1 ▶ if ((val = hv_fetch(hv, "targets", 7, 0))) opt->targets = SvIV(*val);
Branch: 1 branch
BranchTrueFalseTotal
if ((val = hv_fetch(hv, "targets", 7, 0))) opt->targets = SvIV(*val); 1 0 1
25 1 ▶ if ((val = hv_fetch(hv, "use_color", 9, 0))) opt->use_color = SvTRUE(*val);
Branch: 1 branch
BranchTrueFalseTotal
if ((val = hv_fetch(hv, "use_color", 9, 0))) opt->use_color = SvTRUE(*val); 0 1 1
26 1 ▶ if ((val = hv_fetch(hv, "with_rep", 8, 0))) opt->with_rep = SvTRUE(*val);
Branch: 1 branch
BranchTrueFalseTotal
if ((val = hv_fetch(hv, "with_rep", 8, 0))) opt->with_rep = SvTRUE(*val); 0 1 1
27 1 ▶ if ((val = hv_fetch(hv, "show_timestamp", 14, 0))) opt->show_timestamp = SvTRUE(*val);
Branch: 1 branch
BranchTrueFalseTotal
if ((val = hv_fetch(hv, "show_timestamp", 14, 0))) opt->show_timestamp = SvTRUE(*val); 1 0 1
28 1 ▶ if ((val = hv_fetch(hv, "show_log_level", 14, 0))) opt->show_log_level = SvTRUE(*val);
Branch: 1 branch
BranchTrueFalseTotal
if ((val = hv_fetch(hv, "show_log_level", 14, 0))) opt->show_log_level = SvTRUE(*val); 1 0 1
29 1 ▶ if ((val = hv_fetch(hv, "show_file_info", 14, 0))) opt->show_file_info = SvTRUE(*val);
Branch: 1 branch
BranchTrueFalseTotal
if ((val = hv_fetch(hv, "show_file_info", 14, 0))) opt->show_file_info = SvTRUE(*val); 1 0 1
30 1 ▶ if ((val = hv_fetch(hv, "max_file_size", 13, 0))) opt->max_file_size = SvIV(*val);
Branch: 1 branch
BranchTrueFalseTotal
if ((val = hv_fetch(hv, "max_file_size", 13, 0))) opt->max_file_size = SvIV(*val); 0 1 1
31 1 ▶ if ((val = hv_fetch(hv, "max_files", 9, 0))) opt->max_files = SvIV(*val);
Branch: 1 branch
BranchTrueFalseTotal
if ((val = hv_fetch(hv, "max_files", 9, 0))) opt->max_files = SvIV(*val); 0 1 1
32 1 ▶ if ((val = hv_fetch(hv, "flush_immediately", 17, 0))) opt->flush_immediately = SvTRUE(*val);
Branch: 1 branch
BranchTrueFalseTotal
if ((val = hv_fetch(hv, "flush_immediately", 17, 0))) opt->flush_immediately = SvTRUE(*val); 1 0 1
33  
34 1 return opt;
35 }
36  
37 MODULE = XS::Log PACKAGE = XS::Log
38  
39 PROTOTYPES: ENABLE
40  
41 # 打开/关闭/刷新日志
42 bool
43 openLog(filepath, options)
44 const char* filepath
45 HV* options
46 CODE:
47 {
48 1 LogOptions* opt = hv_to_LogOptions(options);
49 1 RETVAL = openLog(filepath, opt);
50 1 ▶ free(opt);
Branch: 1 branch
BranchTrueFalseTotal
free(opt); 1 0 1
51 }
52 OUTPUT: RETVAL
53  
54 void
55 closeLog()
56 CODE:
57 1 closeLog();
58  
59 void
60 flushLog()
61 CODE:
62 1 flushLog();
63  
64 # 包装 bool setLogOptions(const char *key, long val);
65 void
66 setLogOptions(key, val)
67 const char *key
68 long val
69 PREINIT:
70 bool ret;
71 CODE:
72 2 ret = setLogOptions(key, val);
73 2 ▶ if (!ret) {
Branch: 1 branch
BranchTrueFalseTotal
if (!ret) { 1 1 2
74 1 XSRETURN_UNDEF; // 失败返回 undef
75 }
76 // 成功返回 SV* 类型的 true(Perl 中的真值)
77 1 ST(0) = sv_2mortal(newSViv(1));
78  
79  
80 void
81 setLogLevel(flag)
82 int flag
83 CODE:
84 1 setLogLevel(flag);
85  
86 void
87 setLogColor(flag)
88 int flag
89 CODE:
90 1 setLogColor(flag);
91  
92 void
93 setLogMode(flag)
94 int flag
95 CODE:
96 1 setLogMode(flag);
97  
98 void
99 setLogTargets(flag)
100 int flag
101 CODE:
102 1 setLogTargets(flag);
103  
104 int
105 get_show_file_info()
106 CODE:
107 5 ▶ RETVAL = g_config.options.show_file_info;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = g_config.options.show_file_info; 4 1 5
108 OUTPUT:
109 RETVAL
110  
111 void
112 xs_log_write(level, file,line,message)
113 int level
114 SV* file
115 int line
116 SV* message
117 CODE:
118 {
119 STRLEN flen, mlen;
120 6 ▶ const char *cmessage = SvPV(message, mlen);
Branch: 1 branch
BranchTrueFalseTotal
const char *cmessage = SvPV(message, mlen); 6 0 6
121 6 const char *cfile = SvPV(file, flen);
122 6 log_write((LogLevel)level, cfile, line, cmessage);
123 }
124  
125 void
126 xs_rep_write(message)
127 SV* message
128 CODE:
129 {
130 STRLEN flen, mlen;
131 0 const char *cmessage = SvPV(message, mlen);
132 0 rep_write(cmessage);
133 }
« include/Log.c ↑ Summary