2 # Log Printing routines
4 # Copyright (c) - 1998 Dirk Koopman G1TLH
15 use DXDebug qw(dbg isdbg);
23 $readback = `which tac`;
26 #undef $readback; # yet another reason not to use the cloud!
31 use vars qw($maxmonths);
35 # print some items from the log backwards in time
37 # This command outputs a list of n lines starting from time t with $pattern tags
41 my $fcb = $DXLog::log;
42 my $from = shift || 0;
44 my $jdate = $fcb->unixtoj(shift);
51 my $tot = $from + $to;
54 $who = uc $who if defined $who;
57 $hint = q{m{\Q$pattern\E}i};
59 $hint = q{!m{\^(?:ann|rcmd|talk|chat)\^}};
62 $hint .= ' && ' if $hint;
63 $hint .= q{m{\Q$who\E}oi};
65 $hint = "next unless $hint" if $hint;
66 $hint .= "; next unless m{^\\d+\\^$pattern\\^}" if $pattern;
69 $eval = qq(while (<\$fh>) {
74 last L1 if \@in >= $tot;
77 if (isdbg('search')) {
78 dbg("sh/log hint: $hint");
79 dbg("sh/log eval: $eval");
82 $fcb->close; # close any open files
87 my $fn = $fcb->fn($jdate);
88 $fh = IO::File->new("$readback $fn |");
90 $fh = $fcb->open($jdate);
92 L1: for ($months = 0; $fh && $months < $maxmonths && @in < $tot; $months++) {
97 eval $eval; # do the search on this file
98 return ("Log search error", $@) if $@;
102 my $fn = $fcb->fn($jdate->sub(1));
103 $fh = IO::File->new("$readback $fn |");
105 $fh = $fcb->openprev(); # get the next file
110 my $name = $pattern ? $pattern : "log";
111 my $s = "$who "|| '';
112 return "show/$name: ${s}not found";
115 for (sort {$a <=> $b } @in) {
116 my @line = split /\^/ ;
117 push @out, print_item(\@line);
125 # the standard log printing interpreting routine.
127 # every line that is printed should call this routine to be actually visualised
129 # Don't really know whether this is the correct place to put this stuff, but where
132 # I get a reference to an array of items
137 my $d = atime($r->[0]);
140 if ($r->[1] eq 'rcmd') {
141 $r->[6] ||= 'Unknown';
142 if ($r->[2] eq 'in') {
144 $s = "in: $r->[4] ($r->[6] priv: $r->[3]) rcmd: $r->[5]";
147 $s = "$r->[3] $r->[6] reply: $r->[4]";
149 } elsif ($r->[1] eq 'talk') {
151 $s = "$r->[3] -> $r->[2] ($r->[4]) $r->[5]";
152 } elsif ($r->[1] eq 'ann' || $r->[1] eq 'chat') {
154 $r->[4] =~ s/^\#\d+ //;
155 $s = "$r->[3] -> $r->[2] $r->[4]";