From 747266e88f64a9ebfbad5aa4c15244ef121b70cf Mon Sep 17 00:00:00 2001 From: Brian Cully Date: Mon, 13 Nov 2017 19:31:05 +0000 Subject: Move verbose logging to function. --- xmpt | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/xmpt b/xmpt index 7140e8d..f23a3b2 100755 --- a/xmpt +++ b/xmpt @@ -4,11 +4,12 @@ use Data::Dumper; use Getopt::Long; use IO::File; use IPC::Open2; -use v5.10; +use POSIX; use utf8; use strict; use warnings; +use v5.10; our $VERSION = '0'; @@ -170,7 +171,7 @@ sub eval_in { eval { require $_ for @libs; foreach my $plan (@plans) { - print STDERR "[$$] => Executing $plan->{name} step.\n" if $verbose; + verbose("=> Executing $plan->{name} step."); do_send($plan->{name}, @{$plan->{send}}); do_recv($plan->{name}, @{$plan->{expect}}) if $plan->{expect}; } @@ -181,11 +182,7 @@ sub eval_in { sub do_send { my $name = shift; my $s = join('', (map { $_->[1]->() } @_)); - if ($verbose) { - my $l = $s; - chomp $l; - print STDERR "[$$] SEND: $l\n" unless $l =~ /^\s*$/; - } + verbose("SEND: $s"); # TODO: make write SIGPIPE configurable, but for now just ignore it. local $SIG{PIPE} = sub { @@ -237,11 +234,7 @@ sub do_recv { my $n = sysread $evalpkg::in, $r, 2048; die "Error reading data while waiting for match in $name step: $!.\n" if $n == -1; die "End of file while waiting for match in $name step.\n" unless $n; - if ($verbose) { - my $l = $r; - chomp $l; - print STDERR "[$$] RECV: $l\n" - } + verbose("RECV: $r"); $readbuf .= $r; } alarm 0; @@ -251,6 +244,14 @@ sub do_recv { } } +sub verbose { + if ($verbose) { + my $msg = shift; + chomp $msg; + print STDERR strftime('%Y-%m-%d %H:%M:%S', localtime) . " [$$] $msg\n"; + } +} + sub assert_arg { my ($name, $want) = @_; if ($evalpkg::arg) { -- cgit v1.2.3