1
package OpenSRF::Utils::LogServer;
2
use strict; use warnings;
6
use OpenSRF::Utils::Config;
8
use Time::HiRes qw(gettimeofday);
9
use OpenSRF::Utils::Logger;
13
OpenSRF::Utils::LogServer
38
for my $file (@file_info) {
40
close( $file->handle );
48
$config = OpenSRF::Utils::Config->current;
50
unless ($config) { throw OpenSRF::EX::Config ("No suitable config found"); }
52
$port = $config->system->log_port;
53
$proto = $config->system->log_proto;
56
my $server = IO::Socket::INET->new(
59
or die "Error creating server socket : $@\n";
64
my $client = <$server>;
73
my @params = split(/\|/,$client);
74
my $log = shift @params;
76
if( (!$log) || (!@params) ) {
77
warn "Invalid logging params: $log\n";
81
# Put |'s back in since they are stripped
82
# from the message by 'split'
85
foreach my $param (@params) {
86
if( $param ne $params[0] ) {
92
else{ $message = "@params"; }
94
my @lines = split( "\n", $message );
95
my $time = format_time();
99
my ($f_obj) = grep { $_->name eq $log } @file_info;
101
unless( $f_obj and ($fh=$f_obj->handle) ) {
102
my $file = $config->logs->$log;
104
sysopen( $fh, $file, O_WRONLY|O_APPEND|O_CREAT )
105
or warn "Cannot sysopen $log: $!";
108
my $obj = new OpenSRF::Utils::NetLogFile( $log, $file, $fh );
109
push @file_info, $obj;
112
foreach my $line (@lines) {
113
print $fh "$time $line\n" || die "$!";
119
my ($s, $ms) = gettimeofday();
120
my @time = localtime( $s );
121
$ms = substr( $ms, 0, 3 );
122
my $year = $time[5] + 1900;
123
my $mon = $time[4] + 1;
128
$mon = "0" . "$mon" if ( length($mon) == 1 );
129
$day = "0" . "$day" if ( length($day) == 1 );
130
$hour = "0" . "$hour" if ( length($hour) == 1 );
131
$min = "0" . "$min" if (length($min) == 1 );
132
$sec = "0" . "$sec" if (length($sec) == 1 );
135
while( length( $proc ) < 5 ) { $proc = "0" . "$proc"; }
136
return "[$year-$mon-$day $hour:$min:$sec.$ms $proc]";
140
package OpenSRF::Utils::NetLogFile;
142
sub new{ return bless( [ $_[1], $_[2], $_[3] ], $_[0] ); }
144
sub name { return $_[0]->[0]; }
145
sub file { return $_[0]->[1]; }
146
sub handle { return $_[0]->[2]; }