2 # Log Printing routines
4 # Copyright (c) - 1998 Dirk Koopman G1TLH
15 use DXDebug qw(dbg isdbg);
21 our $readback = `which tac`;
23 undef $readback; # yet another reason not to use the cloud!
28 use vars qw($maxmonths);
32 # print some items from the log backwards in time
34 # This command outputs a list of n lines starting from time t with $pattern tags
38 my $fcb = $DXLog::log;
39 my $from = shift || 0;
41 my $jdate = $fcb->unixtoj(shift);
48 my $tot = $from + $to;
51 $who = uc $who if defined $who;
54 $hint = q{m{\Q$pattern\E}i};
56 $hint = q{!m{\^(?:ann|rcmd|talk|chat)\^}};
59 $hint .= ' && ' if $hint;
60 $hint .= q{m{\Q$who\E}oi};
62 $hint = "next unless $hint" if $hint;
63 $hint .= "; next unless m{^\\d+\\^$pattern\\^}" if $pattern;
66 $eval = qq(while (<\$fh>) {
71 last L1 if \@in >= $tot;
74 if (isdbg('search')) {
75 dbg("sh/log hint: $hint");
76 dbg("sh/log eval: $eval");
79 $fcb->close; # close any open files
84 my $fn = $fcb->fn($jdate);
85 $fh = IO::File->new("$readback $fn |");
87 $fh = $fcb->open($jdate);
89 L1: for ($months = 0; $fh && $months < $maxmonths && @in < $tot; $months++) {
94 eval $eval; # do the search on this file
95 return ("Log search error", $@) if $@;
99 my $fn = $fcb->fn($jdate->sub(1));
100 $fh = IO::File->new("$readback $fn |");
102 $fh = $fcb->openprev(); # get the next file
107 my $name = $pattern ? $pattern : "log";
108 my $s = "$who "|| '';
109 return "show/$name: ${s}not found";
113 my @line = split /\^/ ;
114 push @out, print_item(\@line);
122 # the standard log printing interpreting routine.
124 # every line that is printed should call this routine to be actually visualised
126 # Don't really know whether this is the correct place to put this stuff, but where
129 # I get a reference to an array of items
134 my $d = atime($r->[0]);
137 if ($r->[1] eq 'rcmd') {
138 $r->[6] ||= 'Unknown';
139 if ($r->[2] eq 'in') {
141 $s = "in: $r->[4] ($r->[6] priv: $r->[3]) rcmd: $r->[5]";
144 $s = "$r->[3] $r->[6] reply: $r->[4]";
146 } elsif ($r->[1] eq 'talk') {
148 $s = "$r->[3] -> $r->[2] ($r->[4]) $r->[5]";
149 } elsif ($r->[1] eq 'ann' || $r->[1] eq 'chat') {
151 $r->[4] =~ s/^\#\d+ //;
152 $s = "$r->[3] -> $r->[2] $r->[4]";