diff options
author | Gabor X Toth <*@tg-x.net> | 2013-11-01 20:54:40 +0000 |
---|---|---|
committer | Gabor X Toth <*@tg-x.net> | 2013-11-01 20:54:40 +0000 |
commit | 1b28e1d54ca4d0680f02fc35389443ad020d7606 (patch) | |
tree | 2a509122c451f90c2d7b5e3d85b3b1e2602dcf6c /contrib | |
parent | da5c12170ab8ffa5d91a9e704a7060b79ce465fd (diff) | |
download | gnunet-1b28e1d54ca4d0680f02fc35389443ad020d7606.tar.gz gnunet-1b28e1d54ca4d0680f02fc35389443ad020d7606.zip |
logread
Diffstat (limited to 'contrib')
-rwxr-xr-x | contrib/logread.pl | 50 |
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 | |||
7 | use strict; | ||
8 | use warnings; | ||
9 | |||
10 | use Term::ANSIColor qw(:constants :pushpop); | ||
11 | $Term::ANSIColor::AUTOLOCAL = 1; | ||
12 | |||
13 | # Message type numbers to names | ||
14 | my %msgtypes; | ||
15 | my $prefix = $ENV{GNUNET_PREFIX} || '/usr'; | ||
16 | my $filename = "$prefix/include/gnunet/gnunet_protocols.h"; | ||
17 | |||
18 | if (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 | } | ||
26 | else | ||
27 | { | ||
28 | warn "$filename: $!, try setting \$GNUNET_PREFIX"; | ||
29 | } | ||
30 | |||
31 | while (<>) | ||
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 | } | ||