From 02e3b99160c61e5af103d1a8fe8447d94336b6b1 Mon Sep 17 00:00:00 2001 From: Jon Whitear Date: Sun, 6 Mar 2016 11:18:04 +1100 Subject: [PATCH] Socket_Item print _log clean up Replace print statements with &::print_log to provide consistent logging. --- lib/Socket_Item.pm | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/lib/Socket_Item.pm b/lib/Socket_Item.pm index b5ff9c67e..7fffb8f51 100644 --- a/lib/Socket_Item.pm +++ b/lib/Socket_Item.pm @@ -70,8 +70,7 @@ sub new { my $self = { state => '' }; $port_name = $host_port unless $port_name; - print - "\n\nWarning: duplicate ID codes on different socket_Item objects: id=$id\n\n" + &::print_log ("[Socket_Item] WARNING: duplicate ID codes on different Socket_Item objects: id=$id") if $id and $socket_item_by_id{$id}; $$self{port_name} = $port_name; $$self{host_port} = $host_port; @@ -141,10 +140,10 @@ sub start { if ($port) { if ( $main::Socket_Ports{$port_name}{sock} ) { - &::print_log("Socket already opened for $port_name"); + &::print_log ("[Socket_Item] Socket already opened for $port_name"); return $main::Socket_Ports{$port_name}{sock}; } - print "Socket Item connecting to $host on port $port\n" + &::print_log ("[Socket_Item] Connecting to $host on port $port") if $main::Debug{socket}; if ( my $sock = new IO::Socket::INET->new( @@ -163,14 +162,11 @@ sub start { return $sock; } else { - print - "Socket_Item client start error: could not start a tcp client socket\n" - . " - host=$host port=$port: $@\n"; + &::print_log ("[Socket_Item] client start error: could not start a tcp client socket - host=$host port=$port: $@"); } } else { - print - "Socket_Item client start error: address is not in the form host:port. open failed. port=$port_name address=$host_port\n"; + &::print_log ("[Socket_Item] client start error: address is not in the form host:port. Open failed. port=$port_name address $host_port"); } return 0; } @@ -406,15 +402,13 @@ sub set { my $port_name = $self->{port_name}; - print - "Socket_Item: self=$self port=$port_name state=$state ip=$ip_address data=$socket_data\n" + &::print_log ("[Socket_Item] self=$self port=$port_name state=$state ip=$ip_address data=$socket_data") if $main::Debug{socket}; return if $main::Save{mode} and $main::Save{mode} eq 'offline'; unless ( $main::Socket_Ports{$port_name}{sock} ) { - print - "Error, socket port $port_name has not been set: data=$socket_data\n"; + &::print_log ("[Socket_Item] Error, socket port $port_name has not been set: data=$socket_data"); return; } @@ -430,16 +424,14 @@ sub set { $main::Socket_Ports{$port_name}{clients}[$ip_address][0]; } else { - print - "Socket_Item: Error, set client ip number $ip_address is not active\n"; + &::print_log ("[Socket_Item] Error, set client ip number $ip_address is not active"); } } else { for my $ptr ( @{ $main::Socket_Ports{$port_name}{clients} } ) { my ( $socka, $client_ip_address, $client_port, $data ) = @{$ptr}; - print - "Testing socket client ip address: $client_ip_address:$client_port\n" + &::print_log ("[Socket_Item] Testing socket client ip address: $client_ip_address:$client_port") if $main::Debug{socket}; push @sockets, $socka if $socka and $client_ip_address =~ /$ip_address/ @@ -459,8 +451,7 @@ sub set { } unless (@sockets) { - print - "Error, socket port $port_name is not active on a socket_item set for data=$socket_data\n"; + &::print_log ("[Socket_Item] Error, socket port $port_name is not active on a socket_item set for data=$socket_data"); return; } @@ -473,7 +464,7 @@ sub set { for my $sock (@sockets) { next unless $sock; # Shouldn't need this ? - print "db print to $sock: $socket_data\n" if $main::Debug{socket}; + &::print_log ("[Socket_Item] db print to $sock: $socket_data") if $main::Debug{socket}; print $sock $socket_data; } @@ -503,14 +494,14 @@ Used to send a series of strings to the port, waiting for a specified prompt for sub set_expect_check { my ($self) = @_; if ( my $data = said $self) { - print "set_expect: $$self{port_name} said $data\n"; + &::print_log ("[Socket_Item] set_expect: $$self{port_name} said $data"); my $prompt = quotemeta ${ $$self{set_expect_cmds} }[0]; if ( $data =~ /$prompt/i ) { my ( $prompt, $cmd ) = splice @{ $$self{set_expect_cmds} }, 0, 2; - &main::print_log("set_expect: $$self{port_name} $prompt"); + &::print_log ("[Socket_Item] set_expect: $$self{port_name} $prompt"); $self->set( $cmd . "\n" ); unless ( @{ $$self{set_expect_cmds} } ) { - &main::print_log("set_expect: $$self{port_name} done"); + &::print_log ("[Socket_Item] set_expect: $$self{port_name} done"); $self->stop; $$self{set_expect_timer}->unset; &::MainLoop_pre_drop_hook( \&Socket_Item::set_expect_check ); @@ -518,7 +509,7 @@ sub set_expect_check { } } if ( $$self{set_expect_timer}->expired ) { - &main::print_log("set_expect: $$self{port_name} timed out"); + &::print_log ("[Socket_Item] set_expect: $$self{port_name} timed out"); $self->stop; &::MainLoop_pre_drop_hook( \&Socket_Item::set_expect_check ); }