diff --git a/doc/lib/BackRestDoc/Common/DocExecute.pm b/doc/lib/BackRestDoc/Common/DocExecute.pm index 86680a73b..3946d830a 100644 --- a/doc/lib/BackRestDoc/Common/DocExecute.pm +++ b/doc/lib/BackRestDoc/Common/DocExecute.pm @@ -233,32 +233,13 @@ sub execute # Trim off extra linefeeds before and after $strOutput =~ s/^\n+|\n$//g; - - if ($strCommand =~ / pgbackrest /) - { - $strOutput =~ s/^ //smg; - $strOutput =~ s/^[0-9]{4}-[0-1][0-9]-[0-3][0-9] [0-2][0-9]:[0-6][0-9]:[0-6][0-9]\.[0-9]{3} //smg; - } - - # my @stryOutput = split("\n", $strOutput); - # $$hCacheValue{stdout} = \@stryOutput; } if (defined($$hCacheKey{'err-expect'}) && defined($oExec->{strErrorLog}) && $oExec->{strErrorLog} ne '') { - # my $strError = $oExec->{strErrorLog}; - # $strError =~ s/^\n+|\n$//g; - # my @stryError = split("\n", $strError); - # $$hCacheValue{stderr} = \@stryError; - $strOutput .= $oExec->{strErrorLog}; } - # if (defined($$hCacheValue{stderr})) - # { - # $strOutput .= join("\n", @{$$hCacheValue{stderr}}); - # } - if ($$hCacheKey{output} && defined($$hCacheKey{highlight}) && $$hCacheKey{highlight}{filter} && defined($strOutput)) { my $strHighLight = @{$$hCacheKey{highlight}{list}}[0]; @@ -583,6 +564,7 @@ sub backrestConfig # ??? This is not very pretty and should be replaced with a general way to hide config options my $oConfigClean = dclone($self->{config}{$strHostName}{$$hCacheKey{file}}); delete($$oConfigClean{&CONFIG_SECTION_GLOBAL}{&OPTION_LOG_LEVEL_STDERR}); + delete($$oConfigClean{&CONFIG_SECTION_GLOBAL}{&OPTION_LOG_TIMESTAMP}); if (keys(%{$$oConfigClean{&CONFIG_SECTION_GLOBAL}}) == 0) { diff --git a/doc/xml/reference.xml b/doc/xml/reference.xml index c469c6547..ede3618e8 100644 --- a/doc/xml/reference.xml +++ b/doc/xml/reference.xml @@ -68,6 +68,15 @@ error + + + + Enable timestamp in logging. + + Enables the timestamp in console and file logging. This option is disabled in special situations such as generating documentation. + + n + diff --git a/doc/xml/release.xml b/doc/xml/release.xml index 1428f2e0d..0145052f8 100644 --- a/doc/xml/release.xml +++ b/doc/xml/release.xml @@ -308,6 +308,10 @@

Removed --lock option. This option was introduced before the lock directory could be located outside the repository and is now obsolete.

+ + +

Added --log-timestamp option to allow timestamps to be suppressed in logging. This is primarily used to avoid filters in the automated documentation.

+
diff --git a/doc/xml/user-guide.xml b/doc/xml/user-guide.xml index 01862a858..7698434bb 100644 --- a/doc/xml/user-guide.xml +++ b/doc/xml/user-guide.xml @@ -330,7 +330,9 @@ Configure the <postgres/> cluster data directory {[db-path]} + off + n

configuration files follow the Windows INI convention. Sections are denoted by text in brackets and key/value pairs are contained in each section. Lines beginning with # are ignored and can be used as comments.

@@ -1350,6 +1352,7 @@ 2 off + n

The database host must be configured with the backup host/user. The default for the backup-user option is backrest. If the postgres user does restores on the backup host it is best not to also allow the postgres user to perform backups. However, the postgres user can read the repository directly if it is in the same group as the backrest user.

@@ -1367,6 +1370,7 @@ detail off + n

The repository directory will also be removed from the database host. It will not be used anymore so leaving it around may be confusing later on.

@@ -1733,11 +1737,12 @@ {[db-path]} {[backrest-repo-path]} - {[host-backup]} - off standby_mode=on + + off + n

Now the standby can be created with the restore command.

diff --git a/lib/pgBackRest/Common/Log.pm b/lib/pgBackRest/Common/Log.pm index e1ae9b5b6..21657ef0e 100644 --- a/lib/pgBackRest/Common/Log.pm +++ b/lib/pgBackRest/Common/Log.pm @@ -71,6 +71,7 @@ my $strLogFileCache = undef; my $strLogLevelFile = OFF; my $strLogLevelConsole = OFF; my $strLogLevelStdErr = WARN; +my $bLogTimestamp = true; # Flags to limit banner printing until there is actual output my $bLogFileExists; @@ -166,6 +167,7 @@ sub logLevelSet my $strLevelFileParam = shift; my $strLevelConsoleParam = shift; my $strLevelStdErrParam = shift; + my $bLogTimestampParam = shift; # Load FileCommon module require pgBackRest::FileCommon; @@ -200,6 +202,11 @@ sub logLevelSet $strLogLevelStdErr = uc($strLevelStdErrParam); } + + if (defined($bLogTimestampParam)) + { + $bLogTimestamp = $bLogTimestampParam; + } } push @EXPORT, qw(logLevelSet); @@ -630,8 +637,8 @@ sub log my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time); $strMessageFormat = - timestampFormat() . sprintf('.%03d P%02d', (gettimeofday() - int(gettimeofday())) * 1000, - (defined($iProcessId) ? $iProcessId : 0)) . + ($bLogTimestamp ? timestampFormat() . sprintf('.%03d ', (gettimeofday() - int(gettimeofday())) * 1000) : '') . + sprintf('P%02d', defined($iProcessId) ? $iProcessId : 0) . (' ' x (7 - length($strLevel))) . "${strLevel}: ${strMessageFormat}\n"; # Skip output if disabled diff --git a/lib/pgBackRest/Config/Config.pm b/lib/pgBackRest/Config/Config.pm index 1e3c99efb..f5c44c7d4 100644 --- a/lib/pgBackRest/Config/Config.pm +++ b/lib/pgBackRest/Config/Config.pm @@ -285,6 +285,8 @@ use constant OPTION_LOG_LEVEL_FILE => 'log-leve push @EXPORT, qw(OPTION_LOG_LEVEL_FILE); use constant OPTION_LOG_LEVEL_STDERR => 'log-level-stderr'; push @EXPORT, qw(OPTION_LOG_LEVEL_STDERR); +use constant OPTION_LOG_TIMESTAMP => 'log-timestamp'; + push @EXPORT, qw(OPTION_LOG_TIMESTAMP); # ARCHIVE Section #----------------------------------------------------------------------------------------------------------------------------------- @@ -483,6 +485,8 @@ use constant OPTION_DEFAULT_LOG_LEVEL_FILE => lc(INFO); push @EXPORT, qw(OPTION_DEFAULT_LOG_LEVEL_FILE); use constant OPTION_DEFAULT_LOG_LEVEL_STDERR => lc(WARN); push @EXPORT, qw(OPTION_DEFAULT_LOG_LEVEL_STDERR); +use constant OPTION_DEFAULT_LOG_TIMESTAMP => true; + push @EXPORT, qw(OPTION_DEFAULT_LOG_TIMESTAMP); # ARCHIVE SECTION #----------------------------------------------------------------------------------------------------------------------------------- @@ -1366,6 +1370,26 @@ my %oOptionRule = } }, + &OPTION_LOG_TIMESTAMP => + { + &OPTION_RULE_SECTION => CONFIG_SECTION_GLOBAL, + &OPTION_RULE_TYPE => OPTION_TYPE_BOOLEAN, + &OPTION_RULE_DEFAULT => OPTION_DEFAULT_LOG_TIMESTAMP, + &OPTION_RULE_COMMAND => + { + &CMD_ARCHIVE_GET => true, + &CMD_ARCHIVE_PUSH => true, + &CMD_BACKUP => true, + &CMD_CHECK => true, + &CMD_EXPIRE => true, + &CMD_INFO => true, + &CMD_RESTORE => true, + &CMD_STANZA_CREATE => true, + &CMD_START => true, + &CMD_STOP => true + } + }, + # ARCHIVE Section #------------------------------------------------------------------------------------------------------------------------------- &OPTION_ARCHIVE_ASYNC => @@ -1912,7 +1936,8 @@ sub configLogging logLevelSet( optionValid(OPTION_LOG_LEVEL_FILE) ? optionGet(OPTION_LOG_LEVEL_FILE) : OFF, optionValid(OPTION_LOG_LEVEL_CONSOLE) ? optionGet(OPTION_LOG_LEVEL_CONSOLE) : OFF, - optionValid(OPTION_LOG_LEVEL_STDERR) ? optionGet(OPTION_LOG_LEVEL_STDERR) : OFF); + optionValid(OPTION_LOG_LEVEL_STDERR) ? optionGet(OPTION_LOG_LEVEL_STDERR) : OFF, + optionValid(OPTION_LOG_TIMESTAMP) ? optionGet(OPTION_LOG_TIMESTAMP) : undef); $bInitLog = true; } diff --git a/lib/pgBackRest/Config/ConfigHelpData.pm b/lib/pgBackRest/Config/ConfigHelpData.pm index 026896ab0..6ec0d320d 100644 --- a/lib/pgBackRest/Config/ConfigHelpData.pm +++ b/lib/pgBackRest/Config/ConfigHelpData.pm @@ -491,6 +491,18 @@ my $oConfigHelpData = "log path is required." }, + # LOG-TIMESTAMP Option Help + #--------------------------------------------------------------------------------------------------------------------------- + 'log-timestamp' => + { + section => 'log', + summary => + "Enable timestamp in logging.", + description => + "Enables the timestamp in console and file logging. This option is disabled in special situations such as " . + "generating documentation." + }, + # MANIFEST-SAVE-THRESHOLD Option Help #--------------------------------------------------------------------------------------------------------------------------- 'manifest-save-threshold' => @@ -832,6 +844,7 @@ my $oConfigHelpData = 'log-level-file' => 'section', 'log-level-stderr' => 'section', 'log-path' => 'section', + 'log-timestamp' => 'section', 'neutral-umask' => 'section', 'protocol-timeout' => 'section', 'repo-path' => 'section', @@ -871,6 +884,7 @@ my $oConfigHelpData = 'log-level-file' => 'section', 'log-level-stderr' => 'section', 'log-path' => 'section', + 'log-timestamp' => 'section', 'neutral-umask' => 'section', 'process-max' => 'section', 'protocol-timeout' => 'section', @@ -939,6 +953,7 @@ my $oConfigHelpData = 'log-level-file' => 'section', 'log-level-stderr' => 'section', 'log-path' => 'section', + 'log-timestamp' => 'section', 'manifest-save-threshold' => 'section', 'neutral-umask' => 'section', 'online' => 'default', @@ -1018,6 +1033,7 @@ my $oConfigHelpData = 'log-level-file' => 'section', 'log-level-stderr' => 'section', 'log-path' => 'section', + 'log-timestamp' => 'section', 'neutral-umask' => 'section', 'online' => 'default', 'protocol-timeout' => 'section', @@ -1050,6 +1066,7 @@ my $oConfigHelpData = 'log-level-file' => 'section', 'log-level-stderr' => 'section', 'log-path' => 'section', + 'log-timestamp' => 'section', 'repo-path' => 'section', 'retention-archive' => 'section', 'retention-archive-type' => 'section', @@ -1103,6 +1120,7 @@ my $oConfigHelpData = 'log-level-file' => 'section', 'log-level-stderr' => 'section', 'log-path' => 'section', + 'log-timestamp' => 'section', # OUTPUT Option Help #------------------------------------------------------------------------------------------------------------------- @@ -1176,6 +1194,7 @@ my $oConfigHelpData = 'log-level-file' => 'section', 'log-level-stderr' => 'section', 'log-path' => 'section', + 'log-timestamp' => 'section', 'neutral-umask' => 'section', 'process-max' => 'section', 'protocol-timeout' => 'section', @@ -1317,6 +1336,7 @@ my $oConfigHelpData = 'log-level-console' => 'section', 'log-level-file' => 'section', 'log-path' => 'section', + 'log-timestamp' => 'section', 'neutral-umask' => 'section', 'online' => 'default', 'protocol-timeout' => 'section', @@ -1353,6 +1373,7 @@ my $oConfigHelpData = 'log-level-file' => 'section', 'log-level-stderr' => 'section', 'log-path' => 'section', + 'log-timestamp' => 'section', 'repo-path' => 'section', 'stanza' => 'default' } @@ -1401,6 +1422,7 @@ my $oConfigHelpData = 'log-level-file' => 'section', 'log-level-stderr' => 'section', 'log-path' => 'section', + 'log-timestamp' => 'section', 'repo-path' => 'section', 'stanza' => 'default' } diff --git a/test/expect/help-help-001.log b/test/expect/help-help-001.log index ae563c52b..14329459f 100644 --- a/test/expect/help-help-001.log +++ b/test/expect/help-help-001.log @@ -84,6 +84,7 @@ Log Options: --log-level-console level for console logging [default=warn] --log-level-file level for file logging [default=info] --log-level-stderr level for stderr logging [default=warn] + --log-timestamp enable timestamp in logging [default=y] Use 'pgbackrest help info [option]' for more information. diff --git a/test/lib/pgBackRestTest/Common/LogTest.pm b/test/lib/pgBackRestTest/Common/LogTest.pm index 2092a1d29..af4152bdf 100644 --- a/test/lib/pgBackRestTest/Common/LogTest.pm +++ b/test/lib/pgBackRestTest/Common/LogTest.pm @@ -114,15 +114,22 @@ sub logAdd # Do replacements on each line of the log foreach my $strLine (split("\n", $strLog)) { + # Remove timestamp from log line $strLine =~ s/^[0-9]{4}-[0-1][0-9]-[0-3][0-9] [0-2][0-9]:[0-6][0-9]:[0-6][0-9]\.[0-9]{3} //; + # Don't include test points in the final log if ($strLine !~ /^ TEST/) { + # Remove spaces that provided padding for the timetamp $strLine =~ s/^ //; + + # Remove any final CRs $strLine =~ s/\r$//; + # Do other replacements $strLine = $self->regExpReplaceAll($strLine); + # Add to the log $self->{strLog} .= "${strLine}\n"; } }