From 86acbbb85b6eabcb0ff7c86337bff398805aa7ab Mon Sep 17 00:00:00 2001 From: Clemens Schwaighofer Date: Fri, 2 Jun 2023 17:38:09 +0900 Subject: [PATCH] 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. --- www/admin/class_test.logging.php | 18 +++++++++++------- www/lib/CoreLibs/Logging/Logging.php | 14 +++++++------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/www/admin/class_test.logging.php b/www/admin/class_test.logging.php index d93f8f01..ac605abf 100644 --- a/www/admin/class_test.logging.php +++ b/www/admin/class_test.logging.php @@ -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 ""; print "" . $PAGE_NAME . ""; print ""; @@ -44,12 +44,12 @@ print '
Class Test Master
'; print '

' . $PAGE_NAME . '

'; $log->logger2Debug(); - +echo "
"; print "Level 250: " . Level::fromValue(250)->getName() . "
"; -print "Flag: per_run (from int): " . Flag::fromValue(2)->getName() . "
"; -print "Flag: per_run getName(): " . Flag::per_class->getName() . "
"; -print "Flag: per_run ->name: " . Flag::per_class->name . "
"; -print "Flag: per_run ->value: " . Flag::per_class->value . "
"; +print "Flag: per_class (16) (from int): " . Flag::fromValue(16)->getName() . "
"; +print "Flag: per_class getName(): " . Flag::per_class->getName() . "
"; +print "Flag: per_class ->name: " . Flag::per_class->name . "
"; +print "Flag: per_class ->value: " . Flag::per_class->value . "
"; $log->setLogUniqueId(); print "LogUniqId: " . $log->getLogUniqueId() . "
"; @@ -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() . "
"; +$log->setLogFlag(Flag::per_run); +$log->debug('PER RUN', 'per run logging'); +print "Log File: " . $log->getLogFile() . "
"; +$log->unsetLogFlag(Flag::per_run); + // init empty unset($LOG_FILE_ID); $ll = new CoreLibs\Logging\Logging([ diff --git a/www/lib/CoreLibs/Logging/Logging.php b/www/lib/CoreLibs/Logging/Logging.php index 06a4aafd..44e4d3b6 100644 --- a/www/lib/CoreLibs/Logging/Logging.php +++ b/www/lib/CoreLibs/Logging/Logging.php @@ -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(); + } } /**