aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xcontrib/logread-ipc-sdedit.pl59
-rwxr-xr-xcontrib/logread-ipc.sh5
-rwxr-xr-xcontrib/logread.pl56
-rw-r--r--src/util/client.c12
4 files changed, 130 insertions, 2 deletions
diff --git a/contrib/logread-ipc-sdedit.pl b/contrib/logread-ipc-sdedit.pl
new file mode 100755
index 000000000..e482eee30
--- /dev/null
+++ b/contrib/logread-ipc-sdedit.pl
@@ -0,0 +1,59 @@
1#!/usr/bin/env perl
2
3# 1. Start sdedit and enable 'RT diagram server' in 'Global preferences'.
4#
5# 2. Start this tool (see defaults below):
6# gnunet-logread-ipc-sdedit -n buffer-name -i /path/to/ipc.sock -h <sdedit-host> -p <sdedit-port>
7#
8# 3. Start a gnunet-logread instance for each component with the -n <component_name> option
9
10use strict;
11use warnings;
12
13use Getopt::Std;
14use IO::Socket::INET;
15use POSIX qw(mkfifo);
16
17my %opts;
18getopts ('i:n:h:p:', \%opts);
19
20my $ipc = $opts{i} || '/tmp/gnunet-logread-ipc.sock';
21my $name = $opts{n} || 'gnunet';
22my $host = $opts{h} || 'localhost';
23my $port = $opts{p} || 16001;
24my %svcs = map { $_ => 1 } @ARGV;
25
26my $sdedit = IO::Socket::INET->new(PeerAddr => $host,
27 PeerPort => $port,
28 Proto => 'tcp')
29 or die "Cannot connect to $host:$port: $!\n";
30
31print $sdedit "$name\n";
32print $sdedit "_t:time[e]\n";
33print $sdedit "$_:$_\[ap\] \"$_\"\n" for @ARGV;
34print $sdedit "_e:ext[e]\n";
35print $sdedit "\n";
36
37mkfifo $ipc, 0600 or die "$ipc: $!\n" unless -e $ipc;
38open IPC, '<', $ipc or die "$ipc: $!\n";
39while (<IPC>)
40{
41 print;
42 my ($time, $from, $to, $msg, $svc);
43 if (my ($time, $from, $to, $msg) =
44 /^([A-Z][a-z]{2}\ .[0-9]\ [0-9:]{8}(?:-[0-9]{6})?)\s+
45 (\S+)\s+ -> \s+(\S+)\s+ (\S+\s+ \(\d+\))/x)
46 {
47 $from = '_e' unless exists $svcs{$from};
48 $to = '_e' unless exists $svcs{$to};
49 print $sdedit "*0 _t\n$time\n*0\n", "$from:$to.$msg\n"
50 }
51 elsif (($time, $svc, $msg) =
52 /^([A-Z][a-z]{2}\ .[0-9]\ [0-9:]{8}(?:-[0-9]{6})?)\s+
53 (\S+)\s+(.+)/x)
54 {
55 print $sdedit "*0 _t\n$time\n*0\n", "*0 $svc\n$msg\n*0\n"
56 }
57}
58
59close IPC;
diff --git a/contrib/logread-ipc.sh b/contrib/logread-ipc.sh
new file mode 100755
index 000000000..a986c629f
--- /dev/null
+++ b/contrib/logread-ipc.sh
@@ -0,0 +1,5 @@
1#!/bin/sh
2
3ipc=${1:-/tmp/gnunet-logread-ipc.sock}
4test -e "$ipc" || mkfifo "$ipc"
5cat "$ipc"
diff --git a/contrib/logread.pl b/contrib/logread.pl
index a72f7232d..c6f82a68d 100755
--- a/contrib/logread.pl
+++ b/contrib/logread.pl
@@ -3,13 +3,25 @@
3# Usage: 3# Usage:
4# gnunet-service |& gnunet-logread 4# gnunet-service |& gnunet-logread
5# gnunet-logread service.log 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.
6 14
7use strict; 15use strict;
8use warnings; 16use warnings;
9 17
18use Getopt::Std;
10use Term::ANSIColor qw(:constants :pushpop); 19use Term::ANSIColor qw(:constants :pushpop);
11$Term::ANSIColor::AUTOLOCAL = 1; 20$Term::ANSIColor::AUTOLOCAL = 1;
12 21
22my (%opts, $name, $ipc, $msg_level, $msg_regex);
23getopts ('n:i:L:m:', \%opts);
24
13# Message type numbers to names 25# Message type numbers to names
14my %msgtypes; 26my %msgtypes;
15my $prefix = $ENV{GNUNET_PREFIX} || '/usr'; 27my $prefix = $ENV{GNUNET_PREFIX} || '/usr';
@@ -28,8 +40,50 @@ else
28 warn "$filename: $!, try setting \$GNUNET_PREFIX"; 40 warn "$filename: $!, try setting \$GNUNET_PREFIX";
29} 41}
30 42
43my %levels = ( NONE => 0, ERROR => 1, WARNING => 2, INFO => 4, DEBUG => 8 );
44if (exists $opts{n})
45{
46 $name = $opts{n};
47 $ipc = $opts{i} || '/tmp/gnunet-logread-ipc.sock';
48 $msg_level = exists $levels{$opts{L}} ? $levels{$opts{L}} : 0;
49 $msg_regex = $opts{m};
50 print STDERR "RE: /$msg_regex/\n";
51 open IPC, '>', $ipc or die "$ipc: $!\n";
52}
53
31while (<>) 54while (<>)
32{ 55{
56 if (fileno IPC) {
57 my ($time, $type, $size, $from, $to, $level, $msg);
58 if (($time, $type, $size, $from, $to) =
59 /^([A-Z][a-z]{2}\ .[0-9]\ [0-9:]{8}(?:-[0-9]{6})?)\ util-.*\b
60 (?: Received | Transmitting )\ message \b.*?\b
61 type \s+ (\d+) \b.*?\b
62 size \s+ (\d+) \b.*?\b
63 (?: from \s+ (\S+)
64 | to \s+ (\S+) ) /x)
65 {
66 $from ||= $name;
67 $to ||= $name;
68 my ($time, $type, $size, $from, $to) = ($1, $2, $3,
69 $4 || $name, $5 || $name);
70 my $msg = exists $msgtypes{$type} ? $msgtypes{$type} : $type;
71 my $ofh = select IPC;
72 print IPC "$time\t$from -> $to\t$msg ($size)\n";
73 $|++;
74 select $ofh;
75 }
76 if (($time, $level, $msg) =
77 /^([A-Z][a-z]{2}\ .[0-9]\ [0-9:]{8}(?:-[0-9]{6})?)
78 \s+\S+\s+(\S+)\s+(.+)/x
79 and (exists $levels{$level}
80 && $levels{$level} <= $msg_level
81 && (!defined $msg_regex || $msg =~ /$msg_regex/i)))
82 {
83 print IPC "$time\t$name\t$level: $msg\n";
84 }
85 }
86
33 # Timestamp (e.g. Nov 01 19:36:11-384136) 87 # 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; 88 s/^([A-Z][a-z]{2} .[0-9] [0-9:]{8}(?:-[0-9]{6})?)/YELLOW $1/e;
35 89
@@ -50,3 +104,5 @@ while (<>)
50 104
51 print; 105 print;
52} 106}
107
108fileno IPC and close IPC;
diff --git a/src/util/client.c b/src/util/client.c
index 0e6cf0a4f..0a8e99f88 100644
--- a/src/util/client.c
+++ b/src/util/client.c
@@ -573,8 +573,8 @@ receive_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
573 char mbuf[msize]; 573 char mbuf[msize];
574 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) mbuf; 574 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) mbuf;
575 575
576 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received message of type %u and size %u\n", 576 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received message of type %u and size %u from %s service.\n",
577 ntohs (cmsg->type), msize); 577 ntohs (cmsg->type), msize, client->service_name);
578 client->receive_task = GNUNET_SCHEDULER_NO_TASK; 578 client->receive_task = GNUNET_SCHEDULER_NO_TASK;
579 GNUNET_assert (GNUNET_YES == client->msg_complete); 579 GNUNET_assert (GNUNET_YES == client->msg_complete);
580 GNUNET_assert (client->received_pos >= msize); 580 GNUNET_assert (client->received_pos >= msize);
@@ -1148,6 +1148,14 @@ client_notify (void *cls, size_t size, void *buf)
1148 GNUNET_assert (size >= th->size); 1148 GNUNET_assert (size >= th->size);
1149 ret = th->notify (th->notify_cls, size, buf); 1149 ret = th->notify (th->notify_cls, size, buf);
1150 GNUNET_free (th); 1150 GNUNET_free (th);
1151 if (sizeof (struct GNUNET_MessageHeader) <= ret)
1152 {
1153 LOG (GNUNET_ERROR_TYPE_DEBUG,
1154 "Transmitting message of type %u and size %u to %s service.\n",
1155 ntohs (((struct GNUNET_MessageHeader *) buf)->type),
1156 ntohs (((struct GNUNET_MessageHeader *) buf)->size),
1157 client->service_name);
1158 }
1151 return ret; 1159 return ret;
1152} 1160}
1153 1161