-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
getCallerName() moved to Message class
nicer Console logs
- Loading branch information
Showing
3 changed files
with
35 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Class to Log messages to Console. | ||
* | ||
* @author Vitex <[email protected]> | ||
* @copyright 2016 [email protected] (G) | ||
* @copyright 2016-2023 [email protected] (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; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
* Log to stdout/stderr | ||
* | ||
* @author Vitex <[email protected]> | ||
* @copyright 2009-2021 [email protected] (G) | ||
* @copyright 2009-2023 [email protected] (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( | ||
|