aboutsummaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorCarlo von lynX <lynX@time.to.get.psyced.org>2016-05-31 15:13:24 +0000
committerCarlo von lynX <lynX@time.to.get.psyced.org>2016-05-31 15:13:24 +0000
commit91f664dddcbec3f1e337852b52e7faa459e2ab57 (patch)
tree3d3c831d093691489cffb38c5f748f6b1b296681 /contrib
parentacd379f112177d438588d29724eebe10b26bc0c2 (diff)
downloadgnunet-91f664dddcbec3f1e337852b52e7faa459e2ab57.tar.gz
gnunet-91f664dddcbec3f1e337852b52e7faa459e2ab57.zip
added filters to gnunet-logread and an automation fix for gnunet-arm
Diffstat (limited to 'contrib')
-rwxr-xr-xcontrib/gnunet-logread55
1 files changed, 35 insertions, 20 deletions
diff --git a/contrib/gnunet-logread b/contrib/gnunet-logread
index d5c8b1676..1a3650d79 100755
--- a/contrib/gnunet-logread
+++ b/contrib/gnunet-logread
@@ -1,27 +1,36 @@
1#!/usr/bin/env perl 1#!/usr/bin/env perl
2 2# helper tool to make gnunet logs more readable
3# Usage: 3# try 'gnunet-logread -h' for usage
4# gnunet-service |& gnunet-logread
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.
14 4
15use strict; 5use strict;
16use warnings; 6use warnings;
17 7
18use Getopt::Std; 8use Getopt::Std;
9my (%opts, $name, $ipc, $msg_level, $msg_regex);
10getopts ('i:x:n:s:L:m:h', \%opts);
11
12die <<X if $opts{h};
13Usage:
14 <gnunet-service> |& $0 [<options>]
15 or
16 $0 [<options>] <service.log>
17
18Options:
19 Regular screen output options:
20 -i <regex> Include only messages that match regex.
21 -x <regex> Exclude all messages that match regex.
22
23 Options to enable message passing to IPC socket:
24 -n <component_name> Name of this component to use for IPC logging.
25 -s </path/to/ipc.sock> Path to IPC logging socket.
26 -L <LOGLEVEL> Minimum level of messages to pass on.
27 Log levels: NONE, ERROR, WARNING, INFO, DEBUG.
28 -m <regex> Only pass messages matching a regular expression.
29X
30
19use Term::ANSIColor qw(:constants :pushpop); 31use Term::ANSIColor qw(:constants :pushpop);
20$Term::ANSIColor::AUTOLOCAL = 1; 32$Term::ANSIColor::AUTOLOCAL = 1;
21 33
22my (%opts, $name, $ipc, $msg_level, $msg_regex);
23getopts ('n:i:L:m:', \%opts);
24
25# Message type numbers to names 34# Message type numbers to names
26my %msgtypes; 35my %msgtypes;
27my $prefix = $ENV{GNUNET_PREFIX} || '/usr'; 36my $prefix = $ENV{GNUNET_PREFIX} || '/usr';
@@ -34,17 +43,21 @@ if (open HEADER, $filename)
34 $msgtypes{$2} = $1 if /^\s*#define\s+GNUNET_MESSAGE_TYPE_(\w+)\s+(\d+)/i; 43 $msgtypes{$2} = $1 if /^\s*#define\s+GNUNET_MESSAGE_TYPE_(\w+)\s+(\d+)/i;
35 } 44 }
36 close HEADER; 45 close HEADER;
37} 46} else {
38else 47 warn <<X;
39{ 48Could not read $filename for message codes:
40 warn "$filename: $!, try setting \$GNUNET_PREFIX"; 49 $!.
50Please provide a \$GNUNET_PREFIX environment variable to replace "/usr".
51Try also '$0 -h' for help
52
53X
41} 54}
42 55
43my %levels = ( NONE => 0, ERROR => 1, WARNING => 2, INFO => 4, DEBUG => 8 ); 56my %levels = ( NONE => 0, ERROR => 1, WARNING => 2, INFO => 4, DEBUG => 8 );
44if (exists $opts{n}) 57if (exists $opts{n})
45{ 58{
46 $name = $opts{n}; 59 $name = $opts{n};
47 $ipc = $opts{i} || '/tmp/gnunet-logread-ipc.sock'; 60 $ipc = $opts{s} || '/tmp/gnunet-logread-ipc.sock';
48 $msg_level = exists $levels{$opts{L}} ? $levels{$opts{L}} : 0; 61 $msg_level = exists $levels{$opts{L}} ? $levels{$opts{L}} : 0;
49 $msg_regex = $opts{m}; 62 $msg_regex = $opts{m};
50 print STDERR "RE: /$msg_regex/\n" if defined $msg_regex; 63 print STDERR "RE: /$msg_regex/\n" if defined $msg_regex;
@@ -83,6 +96,8 @@ while (<>)
83 print IPC "$time\t$name\t$level: $msg\n"; 96 print IPC "$time\t$name\t$level: $msg\n";
84 } 97 }
85 } 98 }
99 next if $opts{x} and /$opts{x}/io;
100 next if $opts{i} and not /$opts{i}/io;
86 101
87 # Timestamp (e.g. Nov 01 19:36:11-384136) 102 # Timestamp (e.g. Nov 01 19:36:11-384136)
88 s/^([A-Z][a-z]{2} .[0-9] [0-9:]{8}(?:-[0-9]{6})?)/YELLOW $1/e; 103 s/^([A-Z][a-z]{2} .[0-9] [0-9:]{8}(?:-[0-9]{6})?)/YELLOW $1/e;