Compare commits

..

1 Commits

Author SHA1 Message Date
Clemens Schwaighofer
86acbbb85b 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.
2023-06-02 17:38:09 +09:00
2 changed files with 18 additions and 14 deletions

View File

@@ -36,7 +36,7 @@ $log = new CoreLibs\Logging\Logging([
'log_per_date' => true, 'log_per_date' => true,
]); ]);
$PAGE_NAME = 'TEST CLASS: DEBUG LOGGING'; $PAGE_NAME = 'TEST CLASS: LOGGING';
print "<!DOCTYPE html>"; print "<!DOCTYPE html>";
print "<html><head><title>" . $PAGE_NAME . "</title><head>"; print "<html><head><title>" . $PAGE_NAME . "</title><head>";
print "<body>"; 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>'; print '<div><h1>' . $PAGE_NAME . '</h1></div>';
$log->logger2Debug(); $log->logger2Debug();
echo "<hr>";
print "Level 250: " . Level::fromValue(250)->getName() . "<br>"; print "Level 250: " . Level::fromValue(250)->getName() . "<br>";
print "Flag: per_run (from int): " . Flag::fromValue(2)->getName() . "<br>"; print "Flag: per_class (16) (from int): " . Flag::fromValue(16)->getName() . "<br>";
print "Flag: per_run getName(): " . Flag::per_class->getName() . "<br>"; print "Flag: per_class getName(): " . Flag::per_class->getName() . "<br>";
print "Flag: per_run ->name: " . Flag::per_class->name . "<br>"; print "Flag: per_class ->name: " . Flag::per_class->name . "<br>";
print "Flag: per_run ->value: " . Flag::per_class->value . "<br>"; print "Flag: per_class ->value: " . Flag::per_class->value . "<br>";
$log->setLogUniqueId(); $log->setLogUniqueId();
print "LogUniqId: " . $log->getLogUniqueId() . "<br>"; print "LogUniqId: " . $log->getLogUniqueId() . "<br>";
@@ -77,9 +77,13 @@ and > and <
EOM)); EOM));
$log->info('Info message', ['info' => 'log']); $log->info('Info message', ['info' => 'log']);
$log->error('Cannot process data', ['error' => 'log']); $log->error('Cannot process data', ['error' => 'log']);
print "Log File: " . $log->getLogFile() . "<br>"; 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 // init empty
unset($LOG_FILE_ID); unset($LOG_FILE_ID);
$ll = new CoreLibs\Logging\Logging([ $ll = new CoreLibs\Logging\Logging([

View File

@@ -407,13 +407,6 @@ class Logging
} }
$this->setLogFlag($log_flag_key); $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 public function setLogFlag(Flag $flag): void
{ {
$this->log_flags |= $flag->value; $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();
}
} }
/** /**