2 # Log Printing routines
4 # Copyright (c) - 1998 Dirk Koopman G1TLH
15 use DXDebug qw(dbg isdbg);
21 our $readback = `which tac`;
26 use vars qw($maxmonths);
30 # print some items from the log backwards in time
32 # This command outputs a list of n lines starting from time t with $pattern tags
36 my $fcb = $DXLog::log;
37 my $from = shift || 0;
39 my $jdate = $fcb->unixtoj(shift);
46 my $tot = $from + $to;
49 $who = uc $who if defined $who;
52 $hint = q{m{\Q$pattern\E}i};
54 $hint = q{!m{\^(?:ann|rcmd|talk|chat)\^}};
57 $hint .= ' && ' if $hint;
58 $hint .= q{m{\Q$who\E}oi};
60 $hint = "next unless $hint" if $hint;
61 $hint .= "; next unless m{^\\d+\\^$pattern\\^}" if $pattern;
64 $eval = qq(while (<\$fh>) {
69 last L1 if \@in >= $tot;
72 if (isdbg('search')) {
73 dbg("sh/log hint: $hint");
74 dbg("sh/log eval: $eval");
77 $fcb->close; # close any open files
82 my $fn = $fcb->fn($jdate);
83 $fh = IO::File->new("$readback $fn |");
85 $fh = $fcb->open($jdate);
87 L1: for ($months = 0; $fh && $months < $maxmonths && @in < $tot; $months++) {
92 eval $eval; # do the search on this file
93 return ("Log search error", $@) if $@;
97 my $fn = $fcb->fn($jdate->sub(1));
98 $fh = IO::File->new("$readback $fn |");
100 $fh = $fcb->openprev(); # get the next file
105 my $name = $pattern ? $pattern : "log";
106 my $s = "$who "|| '';
107 return "show/$name: ${s}not found";
111 my @line = split /\^/ ;
112 push @out, print_item(\@line);
120 # the standard log printing interpreting routine.
122 # every line that is printed should call this routine to be actually visualised
124 # Don't really know whether this is the correct place to put this stuff, but where
127 # I get a reference to an array of items
132 my $d = atime($r->[0]);
135 if ($r->[1] eq 'rcmd') {
136 $r->[6] ||= 'Unknown';
137 if ($r->[2] eq 'in') {
139 $s = "in: $r->[4] ($r->[6] priv: $r->[3]) rcmd: $r->[5]";
142 $s = "$r->[3] $r->[6] reply: $r->[4]";
144 } elsif ($r->[1] eq 'talk') {
146 $s = "$r->[3] -> $r->[2] ($r->[4]) $r->[5]";
147 } elsif ($r->[1] eq 'ann' || $r->[1] eq 'chat') {
149 $r->[4] =~ s/^\#\d+ //;
150 $s = "$r->[3] -> $r->[2] $r->[4]";