Per run logging was not set if flag changed

if setFlag was set for per_run or per_date the init values where not set

Fixed that on setFlag it is checked if we have per_date or per_run and
then set if not set.

Not that for date, set the flag will set a new date, for per run no.
This commit is contained in:
Clemens Schwaighofer
2023-06-02 17:38:09 +09:00
parent 8e0af7a5f7
commit 86acbbb85b
2 changed files with 18 additions and 14 deletions

View File

@@ -36,7 +36,7 @@ $log = new CoreLibs\Logging\Logging([
'log_per_date' => true,
]);
$PAGE_NAME = 'TEST CLASS: DEBUG LOGGING';
$PAGE_NAME = 'TEST CLASS: LOGGING';
print "<!DOCTYPE html>";
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
print "<body>";
@@ -44,12 +44,12 @@ print '<div><a href="class_test.php">Class Test Master</a></div>';
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
$log->logger2Debug();
echo "<hr>";
print "Level 250: " . Level::fromValue(250)->getName() . "<br>";
print "Flag: per_run (from int): " . Flag::fromValue(2)->getName() . "<br>";
print "Flag: per_run getName(): " . Flag::per_class->getName() . "<br>";
print "Flag: per_run ->name: " . Flag::per_class->name . "<br>";
print "Flag: per_run ->value: " . Flag::per_class->value . "<br>";
print "Flag: per_class (16) (from int): " . Flag::fromValue(16)->getName() . "<br>";
print "Flag: per_class getName(): " . Flag::per_class->getName() . "<br>";
print "Flag: per_class ->name: " . Flag::per_class->name . "<br>";
print "Flag: per_class ->value: " . Flag::per_class->value . "<br>";
$log->setLogUniqueId();
print "LogUniqId: " . $log->getLogUniqueId() . "<br>";
@@ -77,9 +77,13 @@ and > and <
EOM));
$log->info('Info message', ['info' => 'log']);
$log->error('Cannot process data', ['error' => 'log']);
print "Log File: " . $log->getLogFile() . "<br>";
$log->setLogFlag(Flag::per_run);
$log->debug('PER RUN', 'per run logging');
print "Log File: " . $log->getLogFile() . "<br>";
$log->unsetLogFlag(Flag::per_run);
// init empty
unset($LOG_FILE_ID);
$ll = new CoreLibs\Logging\Logging([

View File

@@ -407,13 +407,6 @@ class Logging
}
$this->setLogFlag($log_flag_key);
}
// init per run uid
if ($this->getLogFlag(Flag::per_run)) {
$this->setLogUniqueId();
} elseif ($this->getLogFlag(Flag::per_date)) {
// init file date
$this->log_file_date = date('Y-m-d');
}
}
/**
@@ -776,6 +769,13 @@ class Logging
public function setLogFlag(Flag $flag): void
{
$this->log_flags |= $flag->value;
// init per run uid
if ($this->getLogFlag(Flag::per_run)) {
$this->setLogUniqueId();
} elseif ($this->getLogFlag(Flag::per_date)) {
// init file date
$this->setLogDate();
}
}
/**