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
7 # This library is free software; you can redistribute it and/or
8 # modify it under the same terms as Perl itself.
16 @EXPORT = qw(dbginit dbg dbgadd dbgsub dbglist dbgdump isdbg dbgclose confess croak cluck carp);
20 use vars qw(%dbglevel $fp);
28 # Avoid generating "subroutine redefined" warnings with the following
29 # hack (from CGI::Carp):
30 if (!defined $DB::VERSION) {
32 eval qq( sub confess {
33 \$SIG{__DIE__} = 'DEFAULT';
34 Debug::dbg(\$@, Carp::shortmess(\@_));
38 \$SIG{__DIE__} = 'DEFAULT';
39 Debug::dbg(\$@, Carp::longmess(\@_));
42 sub carp { Debug::dbg(Carp::shortmess(\@_)); }
43 sub cluck { Debug::dbg(Carp::longmess(\@_)); }
46 CORE::die(Carp::shortmess($@)) if $@;
48 eval qq( sub confess { Carp::confess(\@_); }
49 sub cluck { Carp::cluck(\@_); }
50 sub carp { Carp::cluck(\@_); }
59 my $ts = sprintf("%02d:%02d:%02d", (gmtime($t))[2,1,0]);
63 my @l = split /\n/, $r;
65 s/([\x00-\x08\x0B-\x1f\x7f-\xff])/uc sprintf("%%%02x",ord($1))/eg;
66 # print "$_\n" if defined \*STDOUT;
67 $fp->writeunix($t, "$ts $_");
74 # add sig{__DIE__} handling
75 if (!defined $DB::VERSION) {
76 $SIG{__WARN__} = sub { dbg($@, Carp::shortmess(@_)); };
77 $SIG{__DIE__} = sub { dbg($@, Carp::longmess(@_)); };
80 $fp = SMGLog->new('debug', 'log', 'd');
85 $SIG{__DIE__} = $SIG{__WARN__} = 'DEFAULT';
96 for (my $o = 0; $o < length $l; $o += 16) {
97 my $c = substr $l, $o, 16;
98 my $h = unpack "H*", $c;
99 $c =~ s/[\x00-\x1f\x7f-\xff]/./g;
100 my $left = 16 - length $c;
101 $h .= ' ' x (2 * $left) if $left > 0;
102 dbg($p . sprintf("%4d:", $o) . "$h $c");
103 $p = ' ' x (length $p);
112 foreach $entry (@_) {
113 $dbglevel{$entry} = 1;
121 foreach $entry (@_) {
122 delete $dbglevel{$entry};
128 return keys (%dbglevel);
133 return undef unless $fp;
134 return $dbglevel{$_[0]};
139 return Carp::shortmess(@_);
144 return Carp::longmess(@_);