Log.xs

filter: Statementstmt 0.0% 0 / 34 Branchbran 0.0% 0 / 32 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 0.0% 0 / 66 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« blib/lib/XS/Log.pm ↑ Summary
1 /***************************************************************************************
2 * Build MD5 : bTO8KdNuOXUI/qjnYirIyg
3 * Build Time : 2025-09-23 11:51:03
4 * Version : 5.090124
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 0 static LogOptions* hv_to_LogOptions(HV* hv) {
17 0 LogOptions* opt = (LogOptions*)malloc(sizeof(LogOptions));
18 0 ▶ if (!opt) return NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (!opt) return NULL; 0 0 0
19 0 memset(opt, 0, sizeof(LogOptions));
20  
21 SV** val;
22 0 ▶ 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); 0 0 0
23 0 ▶ 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 0 0
24 0 ▶ 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); 0 0 0
25 0 ▶ 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 0 0
26 0 ▶ 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 0 0
27 0 ▶ 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); 0 0 0
28 0 ▶ 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); 0 0 0
29 0 ▶ 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); 0 0 0
30 0 ▶ 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 0 0
31 0 ▶ 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 0 0
32 0 ▶ 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); 0 0 0
33  
34 0 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 0 LogOptions* opt = hv_to_LogOptions(options);
49 0 RETVAL = openLog(filepath, opt);
50 0 ▶ free(opt);
Branch: 1 branch
BranchTrueFalseTotal
free(opt); 0 0 0
51 }
52 OUTPUT: RETVAL
53  
54 void
55 closeLog()
56 CODE:
57 0 closeLog();
58  
59 void
60 flushLog()
61 CODE:
62 0 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 0 ret = setLogOptions(key, val);
73 0 ▶ if (!ret) {
Branch: 1 branch
BranchTrueFalseTotal
if (!ret) { 0 0 0
74 0 XSRETURN_UNDEF; // 失败返回 undef
75 }
76 // 成功返回 SV* 类型的 true(Perl 中的真值)
77 0 ST(0) = sv_2mortal(newSViv(1));
78  
79  
80 void
81 setLogColor(flag)
82 int flag
83 CODE:
84 0 setLogColor(flag);
85  
86 void
87 setLogMode(flag)
88 int flag
89 CODE:
90 0 setLogMode(flag);
91  
92 void
93 setLogTargets(flag)
94 int flag
95 CODE:
96 0 setLogTargets(flag);
97  
98 int
99 get_show_file_info()
100 CODE:
101 0 ▶ RETVAL = g_config.options.show_file_info;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = g_config.options.show_file_info; 0 0 0
102 OUTPUT:
103 RETVAL
104  
105 void
106 xs_log_write(level, file,line,message)
107 int level
108 SV* file
109 int line
110 SV* message
111 CODE:
112 {
113 STRLEN flen, mlen;
114 0 ▶ const char *cmessage = SvPV(message, mlen);
Branch: 1 branch
BranchTrueFalseTotal
const char *cmessage = SvPV(message, mlen); 0 0 0
115 0 const char *cfile = SvPV(file, flen);
116 0 log_write((LogLevel)level, cfile, line, cmessage);
117 }
118  
119 void
120 xs_rep_write(message)
121 SV* message
122 CODE:
123 {
124 STRLEN flen, mlen;
125 0 const char *cmessage = SvPV(message, mlen);
126 0 rep_write(cmessage);
127 }
« blib/lib/XS/Log.pm ↑ Summary