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>
</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>
<p>Moved <code>File->manifest()</code> into the <code>FileCommon.pm</code> module.</p>
</release-item>

View File

@ -72,6 +72,10 @@ my $strLogLevelFile = OFF;
my $strLogLevelConsole = OFF;
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()
my $bLogDisable = 0;
@ -116,25 +120,15 @@ sub logFileSet
filePathCreate(dirname($strFile), '0770', true, true);
$strFile .= '.log';
my $bExists = false;
if (-e $strFile)
{
$bExists = true;
}
$bLogFileExists = -e $strFile ? true : false;
$bLogFileFirst = true;
$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
if (defined($strLogFileCache))
{
logBanner();
syswrite($hLogFile, $strLogFileCache);
undef($strLogFileCache);
}
@ -143,6 +137,27 @@ sub 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
####################################################################################################################################
@ -660,6 +675,7 @@ sub log
{
if (defined($hLogFile))
{
logBanner();
syswrite($hLogFile, $strMessageFormat);
}
else