diff --git a/src/Ease/Logger/Message.php b/src/Ease/Logger/Message.php index 06dfde3..396c2cd 100644 --- a/src/Ease/Logger/Message.php +++ b/src/Ease/Logger/Message.php @@ -126,9 +126,29 @@ public static function getTypeUnicodeSymbol($type, $color = true) default: // Squared Question $symbol = '🯄'; break; - } } return $symbol; } -} + + /** + * Obtain object name from caller object + * + * @param object|string $caller + * + * @return string + */ + public static function getCallerName($caller) + { + if (is_object($caller)) { + if (method_exists($caller, 'getObjectName')) { + $callerName = $caller->getObjectName(); + } else { + $callerName = get_class($caller); + } + } else { + $callerName = strval($caller); + } + return $callerName; + } +} \ No newline at end of file diff --git a/src/Ease/Logger/ToConsole.php b/src/Ease/Logger/ToConsole.php index 20d3754..b12f801 100644 --- a/src/Ease/Logger/ToConsole.php +++ b/src/Ease/Logger/ToConsole.php @@ -1,12 +1,11 @@ - * @copyright 2016 Vitex@hippy.cz (G) + * @copyright 2016-2023 Vitex@hippy.cz (G) */ namespace Ease\Logger; @@ -90,8 +89,7 @@ public static function set($str, $color) { $colorAttrs = explode("+", $color); $ansi_str = ""; - foreach ($colorAttrs as $attr) - { + foreach ($colorAttrs as $attr) { $ansi_str .= "\033[" . self::$ansiCodes[$attr] . "m"; } $ansi_str .= $str . "\033[" . self::$ansiCodes["off"] . "m"; @@ -109,14 +107,10 @@ public static function set($str, $color) */ public function addToLog($caller, $message, $type = 'message') { - $ansiMessage = $this->set( - ' ' . Message::getTypeUnicodeSymbol($type) . ' ' . strip_tags(strval($message)), - self::getTypeColor($type) - ); - $logLine = strftime("%D %T") . ' •' . (is_object($caller) ? (method_exists($caller, 'getObjectName') ? $caller->getObjectName() : get_class($caller) ) : $caller) . '‣ ' . $ansiMessage; + $ansiMessage = $this->set(strip_tags(strval($message)), self::getTypeColor($type)); + $logLine = strftime("%D %T") . ' ' . Message::getTypeUnicodeSymbol($type) . ' •' . Message::getCallerName($caller) . '‣ ' . $ansiMessage; $written = 0; - switch ($type) - { + switch ($type) { case 'error': $written += fputs($this->stderr, $logLine . "\n"); break; @@ -130,12 +124,11 @@ public function addToLog($caller, $message, $type = 'message') /** * Get color code for given message * - * @param string $type mail|warning|error|debug|success + * @param string $type mail|warning|error|debug|success|info */ public static function getTypeColor($type) { - switch ($type) - { + switch ($type) { case 'mail': // Envelope $color = 'blue'; break; @@ -151,6 +144,9 @@ public static function getTypeColor($type) case 'success': // Kytička $color = 'green'; break; + case 'info': // Kytička + $color = 'blue'; + break; default: // i v kroužku $color = 'white'; break; @@ -173,5 +169,4 @@ public static function singleton() } return self::$instance; } - -} +} \ No newline at end of file diff --git a/src/Ease/Logger/ToStd.php b/src/Ease/Logger/ToStd.php index 44b175a..0fe127a 100644 --- a/src/Ease/Logger/ToStd.php +++ b/src/Ease/Logger/ToStd.php @@ -6,7 +6,7 @@ * Log to stdout/stderr * * @author Vitex - * @copyright 2009-2021 Vitex@hippy.cz (G) + * @copyright 2009-2023 Vitex@hippy.cz (G) */ namespace Ease\Logger; @@ -73,26 +73,6 @@ public static function singleton() return self::$instance; } - /** - * Obtain object name from caller object - * - * @param object|string $caller - * - * @return string - */ - public static function getCallerName($caller) { - if (is_object($caller)) { - if (method_exists($caller, 'getObjectName')) { - $callerName = $caller->getObjectName(); - } else { - $callerName = get_class($caller); - } - } else { - $callerName = strval($caller); - } - return $callerName; - } - /** * Zapise zapravu do logu. * @@ -117,7 +97,7 @@ public function addToLog($caller, $message, $type = 'message') } else { $person = $user->getObjectName(); } - $caller = $person . ' ' . self::getCallerName($caller); + $caller = $person . ' ' . Message::getCallerName($caller); } $logLine = ' `' . $caller . '` ' . str_replace(