1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-01-30 05:39:12 +02:00

Log file banner is not output until the first log entry is written.

Suggested by Jens Wilke.
This commit is contained in:
David Steele 2017-02-05 10:37:54 -05:00
parent 2237c3fc1b
commit 55feae645e
2 changed files with 37 additions and 13 deletions

View File

@ -241,6 +241,14 @@
<p>Return proper error code when unable to convert a relative path to an absolute path.</p> <p>Return proper error code when unable to convert a relative path to an absolute path.</p>
</release-item> </release-item>
<release-item>
<release-item-contributor-list>
<release-item-ideator id="wilke.jens"/>
</release-item-contributor-list>
<p>Log file banner is not output until the first log entry is written.</p>
</release-item>
<release-item> <release-item>
<p>Moved <code>File->manifest()</code> into the <code>FileCommon.pm</code> module.</p> <p>Moved <code>File->manifest()</code> into the <code>FileCommon.pm</code> module.</p>
</release-item> </release-item>

View File

@ -72,6 +72,10 @@ my $strLogLevelFile = OFF;
my $strLogLevelConsole = OFF; my $strLogLevelConsole = OFF;
my $strLogLevelStdErr = WARN; my $strLogLevelStdErr = WARN;
# Flags to limit banner printing until there is actual output
my $bLogFileExists;
my $bLogFileFirst;
# Allow log to be globally enabled or disabled with logEnable() and logDisable() # Allow log to be globally enabled or disabled with logEnable() and logDisable()
my $bLogDisable = 0; my $bLogDisable = 0;
@ -116,25 +120,15 @@ sub logFileSet
filePathCreate(dirname($strFile), '0770', true, true); filePathCreate(dirname($strFile), '0770', true, true);
$strFile .= '.log'; $strFile .= '.log';
my $bExists = false; $bLogFileExists = -e $strFile ? true : false;
$bLogFileFirst = true;
if (-e $strFile)
{
$bExists = true;
}
$hLogFile = fileOpen($strFile, O_WRONLY | O_CREAT | O_APPEND, '0660'); $hLogFile = fileOpen($strFile, O_WRONLY | O_CREAT | O_APPEND, '0660');
if ($bExists)
{
syswrite($hLogFile, "\n");
}
syswrite($hLogFile, "-------------------PROCESS START-------------------\n");
# Write out anything that was cached before the file was opened # Write out anything that was cached before the file was opened
if (defined($strLogFileCache)) if (defined($strLogFileCache))
{ {
logBanner();
syswrite($hLogFile, $strLogFileCache); syswrite($hLogFile, $strLogFileCache);
undef($strLogFileCache); undef($strLogFileCache);
} }
@ -143,6 +137,27 @@ sub logFileSet
push @EXPORT, qw(logFileSet); push @EXPORT, qw(logFileSet);
####################################################################################################################################
# logBanner
#
# Output a banner on the first log entry written to a file
####################################################################################################################################
sub logBanner
{
if ($bLogFileFirst)
{
if ($bLogFileExists)
{
syswrite($hLogFile, "\n");
}
syswrite($hLogFile, "-------------------PROCESS START-------------------\n");
}
$bLogFileFirst = false;
}
#################################################################################################################################### ####################################################################################################################################
# logLevelSet - set the log level for file and console # logLevelSet - set the log level for file and console
#################################################################################################################################### ####################################################################################################################################
@ -660,6 +675,7 @@ sub log
{ {
if (defined($hLogFile)) if (defined($hLogFile))
{ {
logBanner();
syswrite($hLogFile, $strMessageFormat); syswrite($hLogFile, $strMessageFormat);
} }
else else