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;
45 $hint = "m{\\Q$pattern\\E}i";
47 $hint = "!m{\\^(?:ann|rcmd|talk|chat)\\^}";
50 $hint .= ' && ' if $hint;
51 $hint .= 'm{\\Q$who\\E}i';
53 $hint = "next unless $hint" if $hint;
54 $hint .= ";next unless /^\\d+\\^$pattern\\^/" if $pattern;
57 $eval = qq(while (<\$fh>) {
63 if (isdbg('search')) {
64 dbg("sh/log hint: $hint");
65 dbg("sh/log eval: $eval");
68 $fcb->close; # close any open files
71 my $fh = $fcb->open($jdate);
72 L1: for ($months = 0; $months < $maxmonths && @in < $tot; $months++) {
74 my $ring = RingBuf->new($tot);
78 eval $eval; # do the search on this file
79 return ("Log search error", $@) if $@;
81 @in = ($ring->readall, @in);
82 last L1 if @in >= $tot;
85 $fh = $fcb->openprev(); # get the next file
89 @in = splice @in, -$tot, $tot if @in > $tot;
92 my @line = split /\^/ ;
93 push @out, print_item(\@line);
101 # the standard log printing interpreting routine.
103 # every line that is printed should call this routine to be actually visualised
105 # Don't really know whether this is the correct place to put this stuff, but where
108 # I get a reference to an array of items
113 my $d = atime($r->[0]);
116 if ($r->[1] eq 'rcmd') {
117 if ($r->[2] eq 'in') {
119 $s = "$r->[4] (priv: $r->[3]) rcmd: $r->[5]";
122 $s = "$r->[3] reply: $r->[4]";
124 } elsif ($r->[1] eq 'talk') {
126 $s = "$r->[3] -> $r->[2] ($r->[4]) $r->[5]";
127 } elsif ($r->[1] eq 'ann' || $r->[1] eq 'chat') {
129 $r->[4] =~ s/^\#\d+ //;
130 $s = "$r->[3] -> $r->[2] $r->[4]";