From df16a33ae306e99dde8765411356e1357c5201d6 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Fri, 13 Nov 2020 13:31:32 -0500 Subject: [PATCH] LP1904233 Improve logger controls sans configs Allow Perl client to specify log level and STDOUT logging when the $logger is instantiated without any configuration information, i.e. the client is not connecting to the OpenSRF network. $logger->set_log_stdout(1); $logger->set_log_level($logger->INFO); Signed-off-by: Bill Erickson --- src/perl/lib/OpenSRF/Utils/Logger.pm | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/perl/lib/OpenSRF/Utils/Logger.pm b/src/perl/lib/OpenSRF/Utils/Logger.pm index 6a662ac..36e0e91 100644 --- a/src/perl/lib/OpenSRF/Utils/Logger.pm +++ b/src/perl/lib/OpenSRF/Utils/Logger.pm @@ -42,6 +42,9 @@ my $logfile_enabled = 1; # are we logging to a file? my $act_logfile_enabled = 1;# are we logging to a file? my $max_log_msg_len = 1536; # SYSLOG default maximum is 2048 +# force stdout logging; useful when not connecting to opensrf +my $log_stdout = 0; + our $logger = "OpenSRF::Utils::Logger"; # log levels @@ -56,16 +59,25 @@ sub ALL { return 100; } my $isclient; # true if we control the osrf_xid +sub set_log_level { + my ($self, $level) = @_; + $loglevel = $level; +} + +sub set_log_stdout { + my ($eslf, $value) = @_; + $log_stdout = $value; +} + # load up our config options sub set_config { my $force = shift; - return if defined $config and !$force; + return if (defined $config || $log_stdout) and !$force; $config = OpenSRF::Utils::Config->current; if( !defined($config) ) { $loglevel = INFO(); - warn "*** Logger found no config. Using STDERR ***\n"; return; } @@ -290,6 +302,8 @@ sub _write_file { if ($file) { sysopen( SINK, $file, O_NONBLOCK|O_WRONLY|O_APPEND|O_CREAT ) or die "Cannot sysopen $file: $!"; + } elsif ($log_stdout) { + open (SINK, ">&1"); # print to STDOUT } else { open (SINK, ">&2"); # print to STDERR as warned } -- 2.11.0