- Handle a dot-dir-containing flist using its parent_ndx value.
[rsync.git] / support / logfilter
blob282914aa08df5816e02f0fc52ca5fd0e7cfe1dca
1 #!/usr/bin/perl
2 # Filter the rsync daemon log messages by module name. The log file can be
3 # in either syslog format or rsync's own log-file format. Note that the
4 # MODULE_NAME parameter is used in a regular-expression match in order to
5 # allow regex wildcards to be used. You can also limit the output by
6 # directory hierarchy in a module. Examples:
8 # logfilter foo /var/log/rsyncd.log # output lines for module foo
9 # logfilter foo/dir /var/log/syslog # limit lines to those in dir of foo
11 use strict;
13 my $match = shift;
14 die "Usage: logfilter MODULE_NAME [LOGFILE ...]\n" unless defined $match;
16 my $syslog_prefix = '\w\w\w +\d+ \d\d:\d\d:\d\d \S+ rsyncd';
17 my $rsyncd_prefix = '\d\d\d\d/\d\d/\d\d \d\d:\d\d:\d\d ';
19 my %pids;
21 while (<>) {
22 my($pid,$msg) = /^(?:$syslog_prefix|$rsyncd_prefix)\[(\d+)\]:? (.*)/o;
23 next unless defined $pid;
24 my($mod_spec) = $msg =~ /^rsync (?:on|to) (\S+) from /;
25 if (defined $mod_spec) {
26 if ($mod_spec =~ /^$match(\/\S*)?$/o) {
27 $pids{$pid} = 1;
28 } else {
29 delete $pids{$pid};
32 next unless $pids{$pid};
33 print $_;