2 # The system variables - those indicated will need to be changed to suit your
3 # circumstances (and callsign)
5 # Copyright (c) 1998 - Dirk Koopman G1TLH
14 @EXPORT = qw(dbginit dbg dbgadd dbgsub dbglist dbgdump isdbg dbgclose confess croak cluck);
17 use vars qw(%dbglevel $fp $callback $cleandays $keepdays);
29 use vars qw($VERSION $BRANCH);
30 $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
31 $BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ || (0,0));
32 $main::build += $VERSION;
33 $main::branch += $BRANCH;
35 # Avoid generating "subroutine redefined" warnings with the following
36 # hack (from CGI::Carp):
37 if (!defined $DB::VERSION) {
39 eval qq( sub confess {
40 \$SIG{__DIE__} = 'DEFAULT';
42 DXDebug::dbg(Carp::shortmess(\@_));
46 \$SIG{__DIE__} = 'DEFAULT';
48 DXDebug::dbg(Carp::longmess(\@_));
51 sub carp { DXDebug::dbg(Carp::shortmess(\@_)); }
52 sub cluck { DXDebug::dbg(Carp::longmess(\@_)); }
55 CORE::die(Carp::shortmess($@)) if $@;
57 eval qq( sub confess { die Carp::longmess(\@_); };
58 sub croak { die Carp::shortmess(\@_); };
59 sub cluck { warn Carp::longmess(\@_); };
60 sub carp { warn Carp::shortmess(\@_); };
72 my @l = split /\n/, $r;
74 s/([\x00-\x08\x0B-\x1f\x7f-\xff])/uc sprintf("%%%02x",ord($1))/eg;
75 print "$_\n" if defined \*STDOUT;
77 &$callback($str) if $callback;
78 $fp->writeunix($t, $str);
87 # add sig{__DIE__} handling
88 if (!defined $DB::VERSION) {
89 $SIG{__WARN__} = sub {
90 if ($_[0] =~ /Deep\s+recursion/i) {
92 dbg(Carp::longmess(@_));
96 dbg(Carp::shortmess(@_));
100 $SIG{__DIE__} = sub { dbg($@); dbg(Carp::longmess(@_)); };
103 $fp = DXLog::new('debug', 'dat', 'd');
108 $SIG{__DIE__} = $SIG{__WARN__} = 'DEFAULT';
117 if ($fp && ($dbglevel{$l} || $l eq 'err')) {
119 for (my $o = 0; $o < length $l; $o += 16) {
120 my $c = substr $l, $o, 16;
121 my $h = unpack "H*", $c;
122 $c =~ s/[\x00-\x1f\x7f-\xff]/./g;
123 my $left = 16 - length $c;
124 $h .= ' ' x (2 * $left) if $left > 0;
125 dbg($m . sprintf("%4d:", $o) . "$h $c");
126 $m = ' ' x (length $m);
136 foreach $entry (@_) {
137 $dbglevel{$entry} = 1;
145 foreach $entry (@_) {
146 delete $dbglevel{$entry};
152 return keys (%dbglevel);
158 return $dbglevel{$_[0]};
163 return Carp::shortmess(@_);
168 return Carp::longmess(@_);
171 # clean out old debug files, stop when you get a gap of more than a month
174 my $date = $fp->unixtoj($main::systime)->sub($keepdays+1);
178 my $fn = $fp->_genfn($date);
185 $date = $date->sub(1);