blib/lib/XS/Log.pm

filter: Statementstmt 54.7% 58 / 106 Branchbran 17.8% 5 / 28 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 10 / 20 Podpod 6.2% 1 / 16 totaltotal 43.5% 74 / 170 CC 15 SCAR 32.3
CC
15
Cov
47%
Colored
90.0
printFail
6.0
printNote
2.0
CRAP 25.4
↑ Summary include/Log.c »
1 package XS::Log;
2 2 our $VERSION = 1.16;
3 2 our $BUILDDATE = "2026-09-14"; #Build Time: 02:14:11
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
7 #颜色设置
8 2 LOG_LEVEL_OFF => 0, # 关闭日志
9 LOG_LEVEL_FATAL => 1, # 严重错误
10 LOG_LEVEL_ERROR => 2, # 错误信息
11 LOG_LEVEL_WARN => 3, # 警告信息
12 LOG_LEVEL_INFO => 4, # 一般信息
13 LOG_LEVEL_TRACE => 5, # 最详细的日志信息
14 LOG_LEVEL_DEBUG => 6, # 调试信息
15 LOG_LEVEL_TEXT => 7, # 原文输出
16 LOG_MODE_CYCLE => 0,
17 LOG_MODE_DAILY => 1,
18 LOG_MODE_HOURLY => 2,
19 LOG_TARGET_CONSOLE => 0x01,
20 LOG_TARGET_FILE => 0x02,
21 LOG_TARGET_SYSLOG => 0x04
22 2 };
23 2 ▶use XSLoader;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 2 require Exporter;
25 2 our @ISA = qw(Exporter);
26  
27 2 our @EXPORT_OK = qw(
28 openLog closeLog flushLog setLogOptions setLogColor setLogMode setLogTargets setLogLevel
29 printNote printBug printInf printWarn printErr printFail printLog printRep
30 LOG_LEVEL_OFF LOG_LEVEL_FATAL LOG_LEVEL_ERROR LOG_LEVEL_WARN LOG_LEVEL_INFO LOG_LEVEL_TRACE LOG_LEVEL_DEBUG LOG_LEVEL_TEXT
31 LOG_MODE_CYCLE LOG_MODE_DAILY LOG_MODE_HOURLY
32 LOG_TARGET_CONSOLE LOG_TARGET_FILE LOG_TARGET_SYSLOG
33 Fatal Error Warn Info Debug Trace Print Colored
34 );
35 # 定义导出标签 :all
36 2 our %EXPORT_TAGS = (
37 all => \@EXPORT_OK,
38 );
39 2 XSLoader::load('XS::Log', $VERSION);
40  
41 #--------------------------------------------
42 # 兼容Log2的相关函数:Fatal Error Warn Info Debug Trace Print Colored
43 #--------------------------------------------
44 0 ▶sub Fatal{my $msg = shift; my ($pkg, $file, $line) = caller;xs_log_write(LOG_LEVEL_ERROR,$file,$line,$msg);}
Subroutine Fatal: not called CC=1 SCAR=6.9
Pod undocumented
45 0 ▶sub Error{my $msg = shift; my ($pkg, $file, $line) = caller;xs_log_write(LOG_LEVEL_ERROR,$file,$line,$msg);}
Subroutine Error: not called CC=1 SCAR=6.9
Pod undocumented
46 0 ▶sub Warn {my $msg = shift; my ($pkg, $file, $line) = caller;xs_log_write(LOG_LEVEL_WARN,$file,$line,$msg);}
Subroutine Warn: not called CC=1 SCAR=6.9
Pod undocumented
47 0 ▶sub Info {my $msg = shift; my ($pkg, $file, $line) = caller;xs_log_write(LOG_LEVEL_INFO,$file,$line,$msg);}
Subroutine Info: not called CC=1 SCAR=6.9
Pod undocumented
48 0 ▶sub Debug{my $msg = shift; my ($pkg, $file, $line) = caller;xs_log_write(LOG_LEVEL_DEBUG,$file,$line,$msg);}
Subroutine Debug: not called CC=1 SCAR=6.9
Pod undocumented
49 0 ▶sub Trace{my $msg = shift; my ($pkg, $file, $line) = caller;xs_log_write(LOG_LEVEL_TRACE,$file,$line,$msg);}
Subroutine Trace: not called CC=1 SCAR=6.9
Pod undocumented
50 0 ▶sub Print{my $msg = shift;xs_log_write(LOG_LEVEL_TEXT,undef,undef,$msg);}
Subroutine Print: not called CC=1 SCAR=6.9
Pod undocumented
51  
52 sub Colored
53 0 ▶{
Subroutine Colored: not called CC=9 SCAR=45.0
Pod undocumented
54 0 my $txt = shift;
55 0 my $color = shift;
56 #\033[30m黑色字\033[0m black
57 #\033[31m红色字\033[0m red
58 #\033[32m绿色字\033[0m green
59 #\033[33m黄色字\033[0m yellow
60 #\033[34m蓝色字\033[0m blue
61 #\033[35m紫色字\033[0m magenta
62 #\033[36m天蓝字\033[0m cyan
63 #\033[37m白色字\033[0m white
64 0 ▶ if(lc($color) eq "black") {$txt = "\033[30m$txt\033[0m";}
Branch: 8 branches
BranchTrueFalseTotal
if (lc $color eq 'black') { } 0 0 0
elsif (lc $color eq 'red') { } 0 0 0
elsif (lc $color eq 'green') { } 0 0 0
elsif (lc $color eq 'yellow') { } 0 0 0
elsif (lc $color eq 'blue') { } 0 0 0
elsif (lc $color eq 'magenta') { } 0 0 0
elsif (lc $color eq 'cyan') { } 0 0 0
elsif (lc $color eq 'white') { } 0 0 0
65 0 elsif(lc($color) eq "red") {$txt = "\033[31m$txt\033[0m";}
66 0 elsif(lc($color) eq "green") {$txt = "\033[32m$txt\033[0m";}
67 0 elsif(lc($color) eq "yellow") {$txt = "\033[33m$txt\033[0m";}
68 0 elsif(lc($color) eq "blue") {$txt = "\033[34m$txt\033[0m";}
69 0 elsif(lc($color) eq "magenta") {$txt = "\033[35m$txt\033[0m";}
70 0 elsif(lc($color) eq "cyan") {$txt = "\033[36m$txt\033[0m";}
71 0 elsif(lc($color) eq "white") {$txt = "\033[37m$txt\033[0m";}
72 else{}
73 0 return $txt;
74 }
75  
76 1 ▶sub printNote {
Subroutine printNote: called CC=2 SCAR=7.1
Pod undocumented
77 1 my ($fmt, @args) = @_;
78 1 my $msg = sprintf($fmt, @args);
79 1 my ($pkg,$file,$line);
80 1 $file = ""; $line = 0;
81 #判断是否调用caller会提速?
82 1 ▶ if(get_show_file_info())
Branch: 1 branch
BranchTrueFalseTotal
if (&get_show_file_info()) 0 1 1
83 {
84 0 ($pkg, $file, $line) = caller;
85 }
86 1 xs_log_write(LOG_LEVEL_TRACE,$file,$line,$msg);
87 }
88 1 ▶sub printBug {
Subroutine printBug: called CC=2 SCAR=7.1
Pod undocumented
89 1 my ($fmt, @args) = @_;
90 1 my $msg = sprintf($fmt, @args);
91 1 my ($pkg,$file,$line);
92 1 $file = ""; $line = 0;
93 #判断是否调用caller会提速?
94 1 ▶ if(get_show_file_info())
Branch: 1 branch
BranchTrueFalseTotal
if (&get_show_file_info()) 0 1 1
95 {
96 0 ($pkg, $file, $line) = caller;
97 }
98 1 xs_log_write(LOG_LEVEL_DEBUG,$file,$line,$msg);
99 }
100 1 ▶sub printInf {
Subroutine printInf: called CC=2 SCAR=7.1
Pod undocumented
101 1 my ($fmt, @args) = @_;
102 1 my $msg = sprintf($fmt, @args);
103 1 my ($pkg,$file,$line);
104 1 $file = ""; $line = 0;
105 #判断是否调用caller会提速?
106 1 ▶ if(get_show_file_info())
Branch: 1 branch
BranchTrueFalseTotal
if (&get_show_file_info()) 0 1 1
107 {
108 0 ($pkg, $file, $line) = caller;
109 }
110 1 xs_log_write(LOG_LEVEL_INFO,$file,$line,$msg);
111 }
112 1 ▶sub printWarn {
Subroutine printWarn: called CC=2 SCAR=7.1
Pod undocumented
113 1 my ($fmt, @args) = @_;
114 1 my $msg = sprintf($fmt, @args);
115 1 my ($pkg,$file,$line);
116 1 $file = ""; $line = 0;
117 #判断是否调用caller会提速?
118 1 ▶ if(get_show_file_info())
Branch: 1 branch
BranchTrueFalseTotal
if (&get_show_file_info()) 0 1 1
119 {
120 0 ($pkg, $file, $line) = caller;
121 }
122 1 xs_log_write(LOG_LEVEL_WARN,$file,$line,$msg);
123 }
124 1 ▶sub printErr {
Subroutine printErr: called CC=2 SCAR=7.1
Pod undocumented
125 1 my ($fmt, @args) = @_;
126 1 my $msg = sprintf($fmt, @args);
127 1 my ($pkg,$file,$line);
128 1 $file = ""; $line = 0;
129 #判断是否调用caller会提速?
130 1 ▶ if(get_show_file_info())
Branch: 1 branch
BranchTrueFalseTotal
if (&get_show_file_info()) 0 1 1
131 {
132 0 ($pkg, $file, $line) = caller;
133 }
134 1 xs_log_write(LOG_LEVEL_ERROR,$file,$line,$msg);
135 }
136 0 ▶sub printFail {
Subroutine printFail: not called CC=2 SCAR=17.9
Pod undocumented
137 0 my ($fmt, @args) = @_;
138 0 my $msg = sprintf($fmt, @args);
139 0 my ($pkg,$file,$line);
140 0 $file = ""; $line = 0;
141 #判断是否调用caller会提速?
142 0 ▶ if(get_show_file_info())
Branch: 1 branch
BranchTrueFalseTotal
if (&get_show_file_info()) 0 0 0
143 {
144 0 ($pkg, $file, $line) = caller;
145 }
146 0 xs_log_write(LOG_LEVEL_FATAL,$file,$line,$msg);
147 }
148 1 ▶sub printLog {
Subroutine printLog: called CC=1 SCAR=0.0
Pod undocumented
149 1 my ($fmt, @args) = @_;
150 1 my $msg = sprintf($fmt, @args);
151 1 xs_log_write(LOG_LEVEL_TEXT,"",0,$msg);
152 }
153  
154 0 ▶sub printRep {
Subroutine printRep: not called CC=1 SCAR=6.9
Pod documented
155 0 my ($fmt, @args) = @_;
156 0 my $msg = sprintf($fmt, @args);
157 0 xs_rep_write($msg);
158 }
159 2 1;
160  
161 __END__
↑ Summary include/Log.c »