From 1a5fa920e6baec14fc092d202839ab16d403b7fb Mon Sep 17 00:00:00 2001 From: David Steele Date: Sat, 10 Dec 2016 09:15:20 -0500 Subject: [PATCH] Improved parameter/result logging in debug/trace functions. --- doc/xml/release.xml | 4 ++ lib/pgBackRest/Common/Log.pm | 124 +++++++++++++++----------------- lib/pgBackRest/Common/String.pm | 11 +-- 3 files changed, 62 insertions(+), 77 deletions(-) diff --git a/doc/xml/release.xml b/doc/xml/release.xml index 9e8fe9fe6..44f381dc0 100644 --- a/doc/xml/release.xml +++ b/doc/xml/release.xml @@ -201,6 +201,10 @@

Code cleanup in preparation for improved stanza-create command.

+ + +

Improved parameter/result logging in debug/trace functions.

+
diff --git a/lib/pgBackRest/Common/Log.pm b/lib/pgBackRest/Common/Log.pm index 640113451..e4823c45c 100644 --- a/lib/pgBackRest/Common/Log.pm +++ b/lib/pgBackRest/Common/Log.pm @@ -353,6 +353,59 @@ sub logDebugProcess return @oyResult; } +#################################################################################################################################### +# logDebugBuild +#################################################################################################################################### +sub logDebugBuild +{ + my $strValue = shift; + + my $rResult; + + # Value is undefined + if (!defined($strValue)) + { + $rResult = \'[undef]'; + } + # Value is not a ref, but return it as a ref for efficiency + elsif (!ref($strValue)) + { + $rResult = \$strValue; + } + # Value is a hash + elsif (ref($strValue) eq 'HASH') + { + my $strValueHash; + + for my $strSubValue (sort(keys(%{$strValue}))) + { + $strValueHash .= + (defined($strValueHash) ? ', ' : '{') . "${strSubValue} => " . ${logDebugBuild($strValue->{$strSubValue})}; + } + + $rResult = \(defined($strValueHash) ? $strValueHash . '}' : '{}'); + } + # Value is an array + elsif (ref($strValue) eq 'ARRAY') + { + my $strValueArray; + + for my $strSubValue (@{$strValue}) + { + $strValueArray .= (defined($strValueArray) ? ', ' : '(') . ${logDebugBuild($strSubValue)}; + } + + $rResult = \(defined($strValueArray) ? $strValueArray . ')' : '()'); + } + # Else some other type ??? For the moment this is forced to object to not make big log changes + else + { + $rResult = \('[object]'); + } + + return $rResult; +} + #################################################################################################################################### # logDebugOut #################################################################################################################################### @@ -383,74 +436,9 @@ sub logDebugOut $strParamSet .= ', '; } - my $strValueRef; - my $bDefault = false; - - if (ref($$oParamHash{$strParam}) eq 'HASH') - { - if (blessed($$oParamHash{$strParam}{value})) - { - $strValueRef = \'[object]'; - } - else - { - if (ref($$oParamHash{$strParam}{value}) eq 'ARRAY') - { - my $strValueArray; - - for my $strValue (@{$$oParamHash{$strParam}{value}}) - { - if (ref($strValue) eq 'ARRAY') - { - my $strSubValueArray; - - for my $strSubValue (@{$strValue}) - { - $strSubValueArray .= - (defined($strSubValueArray) ? ', ' : '(') . - (defined($strSubValue) ? $strSubValue : '[undef]'); - } - - $strValueArray .= (defined($strValueArray) ? ', ' : '(') . - (defined($strSubValueArray) ? $strSubValueArray . ')' : '()'); - } - else - { - $strValueArray .= - (defined($strValueArray) ? ', ' : '(') . (defined($strValue) ? $strValue : '[undef]'); - } - } - - $strValueRef = \(defined($strValueArray) ? $strValueArray . ')' : '()'); - } - else - { - $strValueRef = ref($$oParamHash{$strParam}{value}) ? $$oParamHash{$strParam}{value} : - \$$oParamHash{$strParam}{value}; - - $bDefault = defined($$strValueRef) && - defined($$oParamHash{$strParam}{default}) ? $$oParamHash{$strParam}{default} : false; - } - } - } - # If this is an ARRAY ref then create a comma-separated list - elsif (ref($$oParamHash{$strParam}) eq 'ARRAY') - { - my $strValueArray; - - for my $strValue (@{$$oParamHash{$strParam}{value}}) - { - $strValueArray .= - (defined($strValueArray) ? ', ' : '(') . (defined($strValue) ? $strValue : '[undef]'); - } - - $strValueRef = \(defined($strValueArray) ? $strValueArray . ')' : '()'); - } - # Else get a reference if a reference was not passed - else - { - $strValueRef = ref($$oParamHash{$strParam}) ? $$oParamHash{$strParam} : \$$oParamHash{$strParam}; - } + my $strValueRef = defined($oParamHash->{$strParam}{value}) ? logDebugBuild($oParamHash->{$strParam}{value}) : undef; + my $bDefault = + defined($$strValueRef) && defined($$oParamHash{$strParam}{default}) ? $$oParamHash{$strParam}{default} : false; $strParamSet .= "${strParam} = " . ($bDefault ? '<' : '') . diff --git a/lib/pgBackRest/Common/String.pm b/lib/pgBackRest/Common/String.pm index f1c65e85d..aa9572748 100644 --- a/lib/pgBackRest/Common/String.pm +++ b/lib/pgBackRest/Common/String.pm @@ -63,18 +63,11 @@ push @EXPORT, qw(commonPrefix); #################################################################################################################################### # boolFormat # -# Outut boolean as true or false. +# Output boolean as true or false. #################################################################################################################################### sub boolFormat { - my $bValue; - - if ($bValue) - { - return 'true'; - } - - return 'false'; + return shift() ? 'true' : 'false'; } push @EXPORT, qw(boolFormat);