jablonka.czprosek.czf

hotsanic

Subversion Repositories:
[/] [branches/] [HotSaNIC-0.5.0-pre6/] [lib/] [HotSaNIClog.pm] - Blame information for rev 19

 

Line No. Rev Author Line
11simandl#
2# $Id: HotSaNIClog.pm,v 1.8 2004/07/12 09:55:10 bernisys Exp $
3#
4 
5package HotSaNIClog;
6 
7my @Weekday=("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
8 
9my $MODULE="(unknown)";
10my $TIMESTAMP=0;
11my $DEBUGLEVEL=0;
12my $SECTION="(unknown)";
13 
14my %DEBUG_LEVELS=(
15 # main debugging (rrdtimer - 10 levels usable)
16 MAIN_HEARTBEAT=>1,
17 MAIN_SCAN_MODULES=>2,
18 MAIN_SCAN_MODULES_VERBOSE=>4,
19 MAIN_SIGNAL=>8,
20 MAIN_SIGNAL_VERBOSE=>16,
21 MAIN_CALL_SCRIPT=>32,
22 MAIN_CONFIG=>64,
23 MAIN_VERBOSE=>128,
24 MAIN_USER_2=>256,
25 MAIN_USER_3=>512,
26 # module debugging
27 MODULE_FORK=>1024,
28 MODULE_SAMPLING=>2048,
29 MODULE_DB_UPDATE=>4096,
30 MODULE_VERBOSE=>8192,
31 MODULE_CONFIG=>16384,
32 MODULE_USER_1=>32768,
33 MODULE_USER_2=>65536,
34 MODULE_USER_3=>131072,
35 # SNMP stuff
36 SNMP_VERBOSE=>262144,
37 SNMP_CONFIG=>524288,
38 SNMP_RESULTS=>1048576,
39 SNMP_USER_1=>2097152,
40 SNMP_USER_2=>4194304,
41 SNMP_USER_3=>8388608,
42 # custom levels
43 MAIN=>1023,
44 NOSNMP=>262143-1023,
45 SNMP=>16777215-262143,
46 MODULE=>16777215-1023,
47 VERBOSE=>128+8192,
48 FULL=>16777215
49 );
50 
51my %DEBUG_HELP=(
52 # main debugging (rrdtimer - 10 levels usable)
53 MAIN_HEARTBEAT=>"rrdtimer.pl will log the heartbeat interval (\"main loop running\")",
54 MAIN_SCAN_MODULES=>"rrdtimer.pl will log the calling of the \"call_modules\" subroutine",
55 MAIN_SCAN_MODULES_VERBOSE=>"verbose reporting of module starts",
56 MAIN_SIGNAL=>"log module signalling process",
57 MAIN_SIGNAL_VERBOSE=>"verbose logging of module signalling process",
58 MAIN_CALL_SCRIPT=>"log calling of helper scripts (makeindex, diagrams, convert)",
59 MAIN_CONFIG=>"show main configuration hash on startup",
60 MAIN_VERBOSE=>"verbose rrdtimer reporting",
61 MAIN_USER_2=>"",
62 MAIN_USER_3=>"",
63 # module debugging
64 MODULE_FORK=>"module's forking process",
65 MODULE_SAMPLING=>"give a terse overview about what happens while sampling",
66 MODULE_DB_UPDATE=>"show DB update values",
67 MODULE_VERBOSE=>"verbose module reporting",
68 MODULE_CONFIG=>"show module configuration on startup",
69 MODULE_USER_1=>"",
70 MODULE_USER_2=>"",
71 MODULE_USER_3=>"",
72 # SNMP stuff
73 SNMP_VERBOSE=>"verbose SNMP debugging",
74 SNMP_CONFIG=>"show SNMP configuration",
75 SNMP_RESULTS=>"show results of SNMP query",
76 SNMP_USER_1=>"",
77 SNMP_USER_2=>"",
78 SNMP_USER_3=>"",
79 # custom levels
80 MAIN=>"full rrdtimer debugging",
81 NOSNMP=>"module debugging without SNMP",
82 SNMP=>"full SNMP debugging",
83 MODULE=>"full module debugging",
84 VERBOSE=>"verbose reporting",
85 FULL=>"full debugging"
86 );
87 
88($VERSION = '$Revision: 1.8 $') =~ s/.*(\d+\.\d+).*/$1/;
89 
90sub set_modulename { $MODULE=shift || "(unknown)"; }
91 
92sub check_debuglevel {
93 my $which=shift || 0;
94 my $method=shift || "and";
95 my $result=0;
96 
97 my $mask=16777215;
98 if ($MODULE =~ /^[A-Z]+$/) { $mask=$DEBUG_LEVELS{MODULE}; }
99 elsif ($MODULE =~ /^[a-z]+$/) { $mask=$DEBUG_LEVELS{MAIN}; }
100 my $level=(get_debuglevel($which) & $mask);
101 my $local=($DEBUGLEVEL & $mask);
102 
103 return 1 if ( $level > 0) && (($level & $local) == $level);
104 return 0;
105 }
106 
107sub set_debuglevel {
108 $DEBUGLEVEL=shift || 0;
109 if (HotSaNIClog::check_debuglevel("MAIN_CONFIG,MODULE_CONFIG")) {
110 foreach (sort keys %DEBUG_LEVELS) {
111 if (HotSaNIClog::check_debuglevel($_)) { HotSaNIClog::info("DEBUG: $_"," $DEBUG_HELP{$_}"); }
112 }
113 }
114 }
115 
116sub get_debuglevel {
117 my $items=shift || 0;
118 my $level=0;
119 @ITEMS=split /,/,$items;
120 foreach my $item (@ITEMS) {
121 my $method="";
122 if ($item =~ s/^-(.*)/$1/) { $method="not"; }
123 if (defined $DEBUG_LEVELS{$item}) { $item=$DEBUG_LEVELS{$item}; }
124 if ($item =~ /^[0-9]+$/) {
125 if ($method eq "not") { $level &= (16777215-$item); }
126 else { $level |= $item; }
127 }
128 }
129 return $level;
130 }
131 
132sub set_timestamping {
133 $TIMESTAMP=shift;
134 if (!defined $TIMESTAMP) { $TIMESTAMP=0; }
135 elsif ($TIMESTAMP eq "") { $TIMESTAMP=0; }
136 elsif ($TIMESTAMP < 0) { $TIMESTAMP=0; }
137 elsif ($TIMESTAMP > 2) { $TIMESTAMP=0; }
138 }
139 
140######################################################################
141#
142sub info {
143 for $line (@_) {
144 print_entry(": $line");
145 }
146 }
147 
148######################################################################
149#
150sub warn {
151 $message=shift;
152 if (defined $message) {
153 print_entry(" warning: $message");
154 }
155 if (@_) { info(@_); }
156 }
157 
158######################################################################
159#
160sub error {
161 $message=shift;
162 if (defined $message) {
163 print_entry(" error: $message");
164 }
165 if (@_) { info(@_); }
166 }
167 
168sub print_entry {
169 my $line=shift || "";
170 if ($TIMESTAMP>0) {
171 if ($TIMESTAMP==1) { print "\[".time."\] - "; }
172 else {
173 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
174 $year+=1900;
175 $mon++;
176 if ($mon<10) { $mon="0".$mon; }
177 if ($mday<10) { $mday="0".$mday; }
178 if ($hour<10) { $hour="0".$hour; }
179 if ($min<10) { $min="0".$min; }
180 if ($sec<10) { $sec="0".$sec; }
181 print "\[$Weekday[$wday] $year-$mon-$mday $hour:$min:$sec\] - ";
182 }
183 }
184 print "$MODULE " if ($MODULE ne "(unknown)") and ($MODULE ne "");
185 print "[$$]";
186 print "($SECTION) " if ($SECTION ne "(unknown)") and ($SECTION ne "");
187 print "$line\n";
188 }
189 
1901;
191 

Powered by WebSVN 2.2.1