From: John Merriam Date: Wed, 10 Apr 2019 13:51:54 +0000 (-0400) Subject: LP#1824181: Allow 1st arg to logger to be string or subroutine X-Git-Tag: osrf_rel_3_2_0-beta~12 X-Git-Url: http://git.equinoxoli.org/?p=opensrf-equinox.git;a=commitdiff_plain;h=9a90f826e18b42ce6f508064c3ad68cf6d6c7c0a LP#1824181: Allow 1st arg to logger to be string or subroutine This simple change allows the $msg passed to _log_message in Logger.pm to be either a regular string or a delayed exec subroutine. This is in reaction to LP1823338 where a slow debug logging statement was slowing down SIP checkins even though debug logging was not turned on. With this change you can take this: $log->debug("Available methods\n\t".join("\n\t", keys %{ $_METHODS[$proto] }), INTERNAL); and change it to this: $log->debug(sub{return "Available methods\n\t".join("\n\t", keys %{ $_METHODS[$proto] }) }, INTERNAL); and then that slow debug logging line will not be executed unless debug logging is turned on. Signed-off-by: John Merriam Signed-off-by: Galen Charlton --- diff --git a/src/perl/lib/OpenSRF/Utils/Logger.pm b/src/perl/lib/OpenSRF/Utils/Logger.pm index 157c961..6a662ac 100644 --- a/src/perl/lib/OpenSRF/Utils/Logger.pm +++ b/src/perl/lib/OpenSRF/Utils/Logger.pm @@ -239,6 +239,9 @@ sub _log_message { my( $msg, $level ) = @_; return if $level > $loglevel; + # Allow $msg to be either a normal string or a delayed exec subroutine + $msg = &$msg if (ref($msg) eq 'CODE'); + # apply a sane default service name/tag $logger->set_service($0) unless $service;