10 use POSIX
qw(strftime);
17 Getopt
::Long
::Configure
("pass_through");
23 'stats' => \
$stats_opt,
24 'verbose' => \
$verbose_opt,
27 pod2usage
(-exitval
=> -1, -verbose
=> 0) if $help_opt;
28 pod2usage
(-exitval
=> -2, -verbose
=> 2) if $man_opt;
32 # if the first argument is a file, we'll assume it s a journal file, and
33 # use the PrintingListener
36 $listener_or_code = "LWES::Listeners::EventPrintingListener";
40 $listener_or_code = shift @ARGV;
43 # determine the callback which will process each event
44 my $processEventFunc = getProcessEventFunc
($listener_or_code, \
@ARGV);
46 foreach my $journal (@ARGV)
49 my $log_date = strftime
("%a %b %e %H:%M:%S %Y", localtime ($start));
54 print "$log_date : $journal ";
59 open FH
, "zcat $journal |";
61 # read and parse header
63 while ( read (FH
, $header_bytes, 22) == 22)
65 my $header = bytesToHeader
($header_bytes);
67 # read and parse bytes
69 my $n = read (FH
, $event_bytes, $header->{'PayloadLength'});
70 if (defined ($n) && $n == $header->{'PayloadLength'})
72 my $event = bytesToEvent
($event_bytes);
74 # merge header into event
75 foreach my $h (keys %{$header})
77 unless (exists ($event->{$h}))
79 $event->{$h} = $header->{$h};
84 $processEventFunc->($event);
89 die "malformed or truncated journal";
98 my $end = time()-$start;
99 print "had $num_events events processed in $end seconds\n";
109 lwes-perl-journal-listener - listens for events from a journal
113 lwes-perl-journal-listener [options] [<listener> [<args>] | <code>] <journal(s)>
116 --stats Print information about each file processed
117 -help Brief help message
118 -man Full Documentation
120 <listener> is the name of a perl module which extends the base
121 listener LWES::Listener and provides an initialize and processEvent
122 method. The <args> are passed directly to the listener constructor.
124 code is perl code which is embedded in a function which takes one
125 argument, a reference to a perl hash which contains the contents
126 of the event called $event
134 Print information about how many events were processed and how long it took
139 Print help information
143 Print more verbose help information
149 The lwes-perl-journal-listener is a tool for inspecting LWES events that
150 are in journal files created by the lwes-journaller.
152 There are several ways to use the tool. To just print out events as they
153 are seen it can be invoked as
155 % lwes-perl-journal-listener <journal>
157 Alternatively you can provide a LWES::Listener module as outlined in
158 the lwes-perl-event-listener man page.