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 # Avoid generating "subroutine redefined" warnings with the following
30 # hack (from CGI::Carp):
31 if (!defined $DB::VERSION) {
33 eval qq( sub confess {
34 \$SIG{__DIE__} = 'DEFAULT';
36 DXDebug::dbg(Carp::shortmess(\@_));
40 \$SIG{__DIE__} = 'DEFAULT';
42 DXDebug::dbg(Carp::longmess(\@_));
45 sub carp { DXDebug::dbg(Carp::shortmess(\@_)); }
46 sub cluck { DXDebug::dbg(Carp::longmess(\@_)); }
49 CORE::die(Carp::shortmess($@)) if $@;
51 eval qq( sub confess { die Carp::longmess(\@_); };
52 sub croak { die Carp::shortmess(\@_); };
53 sub cluck { warn Carp::longmess(\@_); };
54 sub carp { warn Carp::shortmess(\@_); };
66 my @l = split /\n/, $r;
68 s/([\x00-\x08\x0B-\x1f\x7f-\xff])/uc sprintf("%%%02x",ord($1))/eg;
69 print "$_\n" if defined \*STDOUT;
71 &$callback($str) if $callback;
72 $fp->writeunix($t, $str);
81 # add sig{__DIE__} handling
82 if (!defined $DB::VERSION) {
83 $SIG{__WARN__} = sub {
84 if ($_[0] =~ /Deep\s+recursion/i) {
86 dbg(Carp::longmess(@_));
90 dbg(Carp::shortmess(@_));
94 $SIG{__DIE__} = sub { dbg($@); dbg(Carp::longmess(@_)); };
97 $fp = DXLog::new('debug', 'dat', 'd');
102 $SIG{__DIE__} = $SIG{__WARN__} = 'DEFAULT';
111 if ($fp && ($dbglevel{$l} || $l eq 'err')) {
113 for (my $o = 0; $o < length $l; $o += 16) {
114 my $c = substr $l, $o, 16;
115 my $h = unpack "H*", $c;
116 $c =~ s/[\x00-\x1f\x7f-\xff]/./g;
117 my $left = 16 - length $c;
118 $h .= ' ' x (2 * $left) if $left > 0;
119 dbg($m . sprintf("%4d:", $o) . "$h $c");
120 $m = ' ' x (length $m);
130 foreach $entry (@_) {
131 $dbglevel{$entry} = 1;
139 foreach $entry (@_) {
140 delete $dbglevel{$entry};
146 return keys (%dbglevel);
152 return $dbglevel{$_[0]};
157 return Carp::shortmess(@_);
162 return Carp::longmess(@_);
165 # clean out old debug files, stop when you get a gap of more than a month
168 my $date = $fp->unixtoj($main::systime)->sub($keepdays+1);
172 my $fn = $fp->_genfn($date);
179 $date = $date->sub(1);