aboutsummaryrefslogtreecommitdiff
path: root/contrib/logread.pl
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/logread.pl')
-rwxr-xr-xcontrib/logread.pl56
1 files changed, 56 insertions, 0 deletions
diff --git a/contrib/logread.pl b/contrib/logread.pl
index a72f7232d..c6f82a68d 100755
--- a/contrib/logread.pl
+++ b/contrib/logread.pl
@@ -3,13 +3,25 @@
3# Usage: 3# Usage:
4# gnunet-service |& gnunet-logread 4# gnunet-service |& gnunet-logread
5# gnunet-logread service.log 5# gnunet-logread service.log
6#
7# Options:
8# -n <component_name> Name of this component to use for IPC logging.
9# -i </path/to/ipc.sock> Path to IPC logging socket.
10# Passing on log messages to IPC socket:
11# -L <LOGLEVEL> Minimum level of messages to pass on.
12# Log levels: NONE, ERROR, WARNING, INFO, DEBUG.
13# -m <regex> Only pass on messages matching a regular expression.
6 14
7use strict; 15use strict;
8use warnings; 16use warnings;
9 17
18use Getopt::Std;
10use Term::ANSIColor qw(:constants :pushpop); 19use Term::ANSIColor qw(:constants :pushpop);
11$Term::ANSIColor::AUTOLOCAL = 1; 20$Term::ANSIColor::AUTOLOCAL = 1;
12 21
22my (%opts, $name, $ipc, $msg_level, $msg_regex);
23getopts ('n:i:L:m:', \%opts);
24
13# Message type numbers to names 25# Message type numbers to names
14my %msgtypes; 26my %msgtypes;
15my $prefix = $ENV{GNUNET_PREFIX} || '/usr'; 27my $prefix = $ENV{GNUNET_PREFIX} || '/usr';
@@ -28,8 +40,50 @@ else
28 warn "$filename: $!, try setting \$GNUNET_PREFIX"; 40 warn "$filename: $!, try setting \$GNUNET_PREFIX";
29} 41}
30 42
43my %levels = ( NONE => 0, ERROR => 1, WARNING => 2, INFO => 4, DEBUG => 8 );
44if (exists $opts{n})
45{
46 $name = $opts{n};
47 $ipc = $opts{i} || '/tmp/gnunet-logread-ipc.sock';
48 $msg_level = exists $levels{$opts{L}} ? $levels{$opts{L}} : 0;
49 $msg_regex = $opts{m};
50 print STDERR "RE: /$msg_regex/\n";
51 open IPC, '>', $ipc or die "$ipc: $!\n";
52}
53
31while (<>) 54while (<>)
32{ 55{
56 if (fileno IPC) {
57 my ($time, $type, $size, $from, $to, $level, $msg);
58 if (($time, $type, $size, $from, $to) =
59 /^([A-Z][a-z]{2}\ .[0-9]\ [0-9:]{8}(?:-[0-9]{6})?)\ util-.*\b
60 (?: Received | Transmitting )\ message \b.*?\b
61 type \s+ (\d+) \b.*?\b
62 size \s+ (\d+) \b.*?\b
63 (?: from \s+ (\S+)
64 | to \s+ (\S+) ) /x)
65 {
66 $from ||= $name;
67 $to ||= $name;
68 my ($time, $type, $size, $from, $to) = ($1, $2, $3,
69 $4 || $name, $5 || $name);
70 my $msg = exists $msgtypes{$type} ? $msgtypes{$type} : $type;
71 my $ofh = select IPC;
72 print IPC "$time\t$from -> $to\t$msg ($size)\n";
73 $|++;
74 select $ofh;
75 }
76 if (($time, $level, $msg) =
77 /^([A-Z][a-z]{2}\ .[0-9]\ [0-9:]{8}(?:-[0-9]{6})?)
78 \s+\S+\s+(\S+)\s+(.+)/x
79 and (exists $levels{$level}
80 && $levels{$level} <= $msg_level
81 && (!defined $msg_regex || $msg =~ /$msg_regex/i)))
82 {
83 print IPC "$time\t$name\t$level: $msg\n";
84 }
85 }
86
33 # Timestamp (e.g. Nov 01 19:36:11-384136) 87 # Timestamp (e.g. Nov 01 19:36:11-384136)
34 s/^([A-Z][a-z]{2} .[0-9] [0-9:]{8}(?:-[0-9]{6})?)/YELLOW $1/e; 88 s/^([A-Z][a-z]{2} .[0-9] [0-9:]{8}(?:-[0-9]{6})?)/YELLOW $1/e;
35 89
@@ -50,3 +104,5 @@ while (<>)
50 104
51 print; 105 print;
52} 106}
107
108fileno IPC and close IPC;