2 # Log Printing routines
4 # Copyright (c) - 1998 Dirk Koopman G1TLH
13 use DXDebug qw(dbg isdbg);
21 use vars qw($maxmonths);
25 # print some items from the log backwards in time
27 # This command outputs a list of n lines starting from time t with $pattern tags
31 my $fcb = $DXLog::log;
32 my $from = shift || 0;
34 my $jdate = $fcb->unixtoj(shift);
41 my $tot = $from + $to;
44 $who = uc $who if defined $who;
47 $hint = "m{\\Q$pattern\\E}i";
49 $hint = "!m{\\^(?:ann|rcmd|talk|chat)\\^}";
52 $hint .= ' && ' if $hint;
53 $hint .= 'm{\\Q$who\\E}i';
55 $hint = "next unless $hint" if $hint;
56 $hint .= ";next unless /^\\d+\\^$pattern\\^/" if $pattern;
59 $eval = qq(while (<\$fh>) {
65 if (isdbg('search')) {
66 dbg("sh/log hint: $hint");
67 dbg("sh/log eval: $eval");
70 $fcb->close; # close any open files
73 my $fh = $fcb->open($jdate);
74 L1: for ($months = 0; $months < $maxmonths && @in < $tot; $months++) {
76 my $ring = RingBuf->new($tot);
80 eval $eval; # do the search on this file
81 return ("Log search error", $@) if $@;
83 @in = ($ring->readall, @in);
84 last L1 if @in >= $tot;
87 $fh = $fcb->openprev(); # get the next file
91 @in = splice @in, -$tot, $tot if @in > $tot;
94 my @line = split /\^/ ;
95 push @out, print_item(\@line);
103 # the standard log printing interpreting routine.
105 # every line that is printed should call this routine to be actually visualised
107 # Don't really know whether this is the correct place to put this stuff, but where
110 # I get a reference to an array of items
115 my $d = atime($r->[0]);
118 if ($r->[1] eq 'rcmd') {
119 $r->[6] ||= 'Unknown';
120 if ($r->[2] eq 'in') {
122 $s = "in: $r->[4] ($r->[6] priv: $r->[3]) rcmd: $r->[5]";
125 $s = "$r->[3] $r->[6] reply: $r->[4]";
127 } elsif ($r->[1] eq 'talk') {
129 $s = "$r->[3] -> $r->[2] ($r->[4]) $r->[5]";
130 } elsif ($r->[1] eq 'ann' || $r->[1] eq 'chat') {
132 $r->[4] =~ s/^\#\d+ //;
133 $s = "$r->[3] -> $r->[2] $r->[4]";