Compare commits

...

2 Commits

Author SHA1 Message Date
Clemens Schwaighofer
d06769c48b empty admin folder page for edit base page creation tests 2023-09-27 11:38:32 +09:00
Clemens Schwaighofer
4c0390f082 ErrorMessage class: add notice for non error logging to log file
info is already used for write back to front. So we use notice for
non error level messages into the log file
2023-09-27 11:37:26 +09:00
4 changed files with 36 additions and 0 deletions

View File

@@ -44,6 +44,11 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
'str' => 'INFO', 'str' => 'INFO',
'expected' => 'info', 'expected' => 'info',
], ],
'notice' => [
'level' => 'notice',
'str' => 'NOTICE',
'expected' => 'notice',
],
'warn' => [ 'warn' => [
'level' => 'warn', 'level' => 'warn',
'str' => 'WARN', 'str' => 'WARN',
@@ -238,6 +243,22 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
'log_error' => true, 'log_error' => true,
'expected' => '<ERROR> OTHER ERROR MESSAGE', 'expected' => '<ERROR> OTHER ERROR MESSAGE',
], ],
'notice' => [
'id' => '100',
'level' => 'notice',
'str' => 'NOTICE MESSAGE',
'message' => null,
'log_error' => null,
'expected' => '<NOTICE> NOTICE MESSAGE',
],
'notice, message' => [
'id' => '100',
'level' => 'notice',
'str' => 'NOTICE MESSAGE',
'message' => 'OTHER NOTICE MESSAGE',
'log_error' => null,
'expected' => '<NOTICE> OTHER NOTICE MESSAGE',
],
'crash' => [ 'crash' => [
'id' => '300', 'id' => '300',
'level' => 'crash', 'level' => 'crash',

View File

@@ -0,0 +1,6 @@
<?php
// empty file for add and remove test
// __END__

View File

@@ -42,6 +42,7 @@ class ErrorMessage
* error_id: internal Error ID (should be unique) * error_id: internal Error ID (should be unique)
* level: error level, can only be ok, info, warn, error, abort, crash * level: error level, can only be ok, info, warn, error, abort, crash
* ok and info are positive response: success * ok and info are positive response: success
* notice: a debug message for information only
* warn: success, but there might be some things that are not 100% ok * warn: success, but there might be some things that are not 100% ok
* error: input error or error in executing request * error: input error or error in executing request
* abort: an internal error happened as mandatory information that normally is * abort: an internal error happened as mandatory information that normally is
@@ -98,6 +99,12 @@ class ErrorMessage
]; ];
// write to log for abort/crash // write to log for abort/crash
switch ($level) { switch ($level) {
case 'notice':
$this->log->notice($message ?? $str, array_merge([
'id' => $error_id,
'level' => $original_level,
], $context));
break;
case 'error': case 'error':
if ($log_error) { if ($log_error) {
$this->log->error($message ?? $str, array_merge([ $this->log->error($message ?? $str, array_merge([

View File

@@ -15,6 +15,7 @@ enum MessageLevel: int
{ {
case ok = 100; case ok = 100;
case info = 200; case info = 200;
case notice = 250;
case warn = 300; case warn = 300;
case error = 400; case error = 400;
case abort = 500; case abort = 500;
@@ -30,6 +31,7 @@ enum MessageLevel: int
return match (strtolower($name)) { return match (strtolower($name)) {
'ok' => self::ok, 'ok' => self::ok,
'info' => self::info, 'info' => self::info,
'notice' => self::notice,
'warn', 'warning' => self::warn, 'warn', 'warning' => self::warn,
'error' => self::error, 'error' => self::error,
'abort' => self::abort, 'abort' => self::abort,