From 0722057eaa3b7097fba3c9f92f6a0c99b9fc39e1 Mon Sep 17 00:00:00 2001 From: Patrick Niebeling Date: Sat, 12 Apr 2025 20:37:20 +0200 Subject: [PATCH] Update Logger --- Logger.php | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/Logger.php b/Logger.php index 6e5cde2..a1f3bac 100644 --- a/Logger.php +++ b/Logger.php @@ -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 "
{$timeLog}{$pathLog}{$lineLog}: {$severityLog} - {$messageLog} {$contextLog}
"; + } + } + // Close file stream static::closeFile(); } @@ -353,5 +364,4 @@ class Logger */ private function __destruct() { } -} - \ No newline at end of file +} \ No newline at end of file -- 2.49.0