aboutsummaryrefslogtreecommitdiff
path: root/contrib/logread.pl
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/logread.pl')
-rwxr-xr-xcontrib/logread.pl50
1 files changed, 50 insertions, 0 deletions
diff --git a/contrib/logread.pl b/contrib/logread.pl
new file mode 100755
index 000000000..8602a83e1
--- /dev/null
+++ b/contrib/logread.pl
@@ -0,0 +1,50 @@
1#!/usr/bin/env perl
2
3# Usage:
4# gnunet-service |& gnunet-logread
5# gnunet-logread service.log
6
7use strict;
8use warnings;
9
10use Term::ANSIColor qw(:constants :pushpop);
11$Term::ANSIColor::AUTOLOCAL = 1;
12
13# Message type numbers to names
14my %msgtypes;
15my $prefix = $ENV{GNUNET_PREFIX} || '/usr';
16my $filename = "$prefix/include/gnunet/gnunet_protocols.h";
17
18if (open HEADER, $filename)
19{
20 while (<HEADER>)
21 {
22 $msgtypes{$2} = $1 if /^\s*#define\s+GNUNET_MESSAGE_TYPE_(\w+)\s+(\d+)/i;
23 }
24 close HEADER;
25}
26else
27{
28 warn "$filename: $!, try setting \$GNUNET_PREFIX";
29}
30
31while (<>)
32{
33 # 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;
35
36 # Log levels
37 s/\b(ERROR )\b/RED $1/ex;
38 s/\b(WARNING)\b/YELLOW $1/ex;
39 s/\b(INFO )\b/GREEN $1/ex;
40 s/\b(DEBUG )\b/BRIGHT_BLACK $1/ex;
41
42 # Service names
43 # TODO: might read the list from $GNUNET_PREFIX/libexec/gnunet/
44 s/\b(multicast|psyc|psycstore|social)\b/BLUE $1/ex;
45
46 # Add message type names
47 s/(message(?:\s+of)?\s+type\s+)(\d+)/$1 . BRIGHT_CYAN "$msgtypes{$2}" . CYAN " ($2)"/e;
48
49 print;
50}