summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorGabor X Toth <*@tg-x.net>2013-11-01 20:54:40 +0000
committerGabor X Toth <*@tg-x.net>2013-11-01 20:54:40 +0000
commit1b28e1d54ca4d0680f02fc35389443ad020d7606 (patch)
tree2a509122c451f90c2d7b5e3d85b3b1e2602dcf6c /contrib
parentda5c12170ab8ffa5d91a9e704a7060b79ce465fd (diff)
logread
Diffstat (limited to 'contrib')
-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 @@
+#!/usr/bin/env perl
+
+# Usage:
+# gnunet-service |& gnunet-logread
+# gnunet-logread service.log
+
+use strict;
+use warnings;
+
+use Term::ANSIColor qw(:constants :pushpop);
+$Term::ANSIColor::AUTOLOCAL = 1;
+
+# Message type numbers to names
+my %msgtypes;
+my $prefix = $ENV{GNUNET_PREFIX} || '/usr';
+my $filename = "$prefix/include/gnunet/gnunet_protocols.h";
+
+if (open HEADER, $filename)
+{
+ while (<HEADER>)
+ {
+ $msgtypes{$2} = $1 if /^\s*#define\s+GNUNET_MESSAGE_TYPE_(\w+)\s+(\d+)/i;
+ }
+ close HEADER;
+}
+else
+{
+ warn "$filename: $!, try setting \$GNUNET_PREFIX";
+}
+
+while (<>)
+{
+ # Timestamp (e.g. Nov 01 19:36:11-384136)
+ s/^([A-Z][a-z]{2} .[0-9] [0-9:]{8}(?:-[0-9]{6})?)/YELLOW $1/e;
+
+ # Log levels
+ s/\b(ERROR )\b/RED $1/ex;
+ s/\b(WARNING)\b/YELLOW $1/ex;
+ s/\b(INFO )\b/GREEN $1/ex;
+ s/\b(DEBUG )\b/BRIGHT_BLACK $1/ex;
+
+ # Service names
+ # TODO: might read the list from $GNUNET_PREFIX/libexec/gnunet/
+ s/\b(multicast|psyc|psycstore|social)\b/BLUE $1/ex;
+
+ # Add message type names
+ s/(message(?:\s+of)?\s+type\s+)(\d+)/$1 . BRIGHT_CYAN "$msgtypes{$2}" . CYAN " ($2)"/e;
+
+ print;
+}