Merge pull request 'Update Logger' (#2) from 2025-02-16 into master

Reviewed-on: #2
This commit is contained in:
2025-04-12 18:41:08 +00:00

View File

@ -2,10 +2,10 @@
/**
* @author gnilebein
* @since March 10, 2022
* @since March 12, 2025
* @link https://gitea.gnilebein.de/gnilebein/Simple-PHP-Logger
* @license MIT
* @version 1.0.0
* @version 1.1.0
*
* Description:
* The simple php logger is a single-file logwriter with the features of:
@ -48,7 +48,8 @@ class Logger
protected static $options = [
'dateFormat' => 'd-M-Y',
'logFormat' => 'H:i:s d-M-Y',
'logFileName' => 'log'
'logFileName' => 'log',
'displayOutput' => false // NEU: Steuerung der Ausgabe auf Konsole oder Browser
];
private static $instance;
@ -278,6 +279,16 @@ class Logger
// Write time, url, & message to end of file
fwrite(static::$file, "{$timeLog}{$pathLog}{$lineLog}: {$severityLog} - {$messageLog} {$contextLog}" . PHP_EOL);
// Falls displayOutput aktiv ist, log auch ausgeben
if (!empty(static::$options['displayOutput']) && static::$options['displayOutput'] === true) {
// Für CLI oder Web passend ausgeben
if (static::isCLI()) {
echo "{$timeLog}{$pathLog}{$lineLog}: {$severityLog} - {$messageLog} {$contextLog}" . PHP_EOL;
} else {
echo "<pre>{$timeLog}{$pathLog}{$lineLog}: {$severityLog} - {$messageLog} {$contextLog}</pre>";
}
}
// Close file stream
static::closeFile();
}
@ -354,4 +365,3 @@ class Logger
private function __destruct()
{ }
}