From 91f664dddcbec3f1e337852b52e7faa459e2ab57 Mon Sep 17 00:00:00 2001 From: Carlo von lynX Date: Tue, 31 May 2016 15:13:24 +0000 Subject: [PATCH] added filters to gnunet-logread and an automation fix for gnunet-arm --- contrib/gnunet-logread | 55 +++++++++++++++++++++++++++--------------- src/arm/gnunet-arm.c | 3 ++- 2 files changed, 37 insertions(+), 21 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 @@ #!/usr/bin/env perl - -# Usage: -# gnunet-service |& gnunet-logread -# gnunet-logread service.log -# -# Options: -# -n Name of this component to use for IPC logging. -# -i Path to IPC logging socket. -# Passing on log messages to IPC socket: -# -L Minimum level of messages to pass on. -# Log levels: NONE, ERROR, WARNING, INFO, DEBUG. -# -m Only pass on messages matching a regular expression. +# helper tool to make gnunet logs more readable +# try 'gnunet-logread -h' for usage use strict; use warnings; use Getopt::Std; +my (%opts, $name, $ipc, $msg_level, $msg_regex); +getopts ('i:x:n:s:L:m:h', \%opts); + +die < |& $0 [] + or + $0 [] + +Options: + Regular screen output options: + -i Include only messages that match regex. + -x Exclude all messages that match regex. + + Options to enable message passing to IPC socket: + -n Name of this component to use for IPC logging. + -s Path to IPC logging socket. + -L Minimum level of messages to pass on. + Log levels: NONE, ERROR, WARNING, INFO, DEBUG. + -m Only pass messages matching a regular expression. +X + use Term::ANSIColor qw(:constants :pushpop); $Term::ANSIColor::AUTOLOCAL = 1; -my (%opts, $name, $ipc, $msg_level, $msg_regex); -getopts ('n:i:L:m:', \%opts); - # Message type numbers to names my %msgtypes; my $prefix = $ENV{GNUNET_PREFIX} || '/usr'; @@ -34,17 +43,21 @@ if (open HEADER, $filename) $msgtypes{$2} = $1 if /^\s*#define\s+GNUNET_MESSAGE_TYPE_(\w+)\s+(\d+)/i; } close HEADER; -} -else -{ - warn "$filename: $!, try setting \$GNUNET_PREFIX"; +} else { + warn < 0, ERROR => 1, WARNING => 2, INFO => 4, DEBUG => 8 ); if (exists $opts{n}) { $name = $opts{n}; - $ipc = $opts{i} || '/tmp/gnunet-logread-ipc.sock'; + $ipc = $opts{s} || '/tmp/gnunet-logread-ipc.sock'; $msg_level = exists $levels{$opts{L}} ? $levels{$opts{L}} : 0; $msg_regex = $opts{m}; print STDERR "RE: /$msg_regex/\n" if defined $msg_regex; @@ -83,6 +96,8 @@ while (<>) print IPC "$time\t$name\t$level: $msg\n"; } } + next if $opts{x} and /$opts{x}/io; + next if $opts{i} and not /$opts{i}/io; # 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; diff --git a/src/arm/gnunet-arm.c b/src/arm/gnunet-arm.c index 4501ed036..75ade59da 100644 --- a/src/arm/gnunet-arm.c +++ b/src/arm/gnunet-arm.c @@ -544,7 +544,8 @@ list_callback (void *cls, ret = 3; return; } - FPRINTF (stdout, "%s", _("Running services:\n")); + if (! quiet) + FPRINTF (stdout, "%s", _("Running services:\n")); for (i = 0; i < count; i++) FPRINTF (stdout, "%s\n", list[i]); al_task = GNUNET_SCHEDULER_add_now (&action_loop, NULL); -- 2.25.1