1515use Koded \Logging \Processors \{Cli , Processor };
1616use DateTimeZone ;
1717use Psr \Log \LoggerTrait ;
18+ use Stringable ;
1819use Throwable ;
20+ use function constant ;
21+ use function date_create_immutable ;
22+ use function spl_object_id ;
23+ use function strtoupper ;
24+ use function strtr ;
25+ use function timezone_open ;
1926
2027/**
2128 * Class Log for logging different types of application messages.
@@ -78,17 +85,17 @@ public function __construct(
7885 private string $ dateformat = self ::DATE_FORMAT ,
7986 string $ timezone = 'UTC ' )
8087 {
81- $ this ->timezone = @\ timezone_open ($ timezone ) ?: \ timezone_open ('UTC ' );
88+ $ this ->timezone = @timezone_open ($ timezone ) ?: timezone_open ('UTC ' );
8289 foreach ($ processors as $ processor ) {
8390 $ this ->attach (new $ processor ['class ' ]($ processor ));
8491 }
8592 }
8693
87- public function log ($ level , $ message , array $ context = []): void
94+ public function log ($ level , string | Stringable $ message , array $ context = []): void
8895 {
8996 try {
90- $ levelName = \ strtoupper ($ level );
91- $ level = \ constant ('static:: ' . $ levelName );
97+ $ levelName = strtoupper ($ level );
98+ $ level = constant ('static:: ' . $ levelName );
9299 } catch (Throwable ) {
93100 $ levelName = 'LOG ' ;
94101 $ level = -1 ;
@@ -106,21 +113,21 @@ public function log($level, $message, array $context = []): void
106113 public function attach (Processor $ processor ): Logger
107114 {
108115 if (0 !== $ processor ->levels ()) {
109- $ this ->processors [\ spl_object_id ($ processor )] = $ processor ;
116+ $ this ->processors [spl_object_id ($ processor )] = $ processor ;
110117 }
111118 return $ this ;
112119 }
113120
114121 public function detach (Processor $ processor ): Logger
115122 {
116- unset($ this ->processors [\ spl_object_id ($ processor )]);
123+ unset($ this ->processors [spl_object_id ($ processor )]);
117124 return $ this ;
118125 }
119126
120127 public function exception (Throwable $ e , Processor $ processor = null ): void
121128 {
122129 $ this ->attach ($ processor ??= new Cli ([]));
123- $ this ->critical ($ e ->getMessage () . PHP_EOL . ' -- [Trace]: ' . $ e ->getTraceAsString ());
130+ $ this ->critical ($ e ->getMessage () . PHP_EOL . ' [Trace]: ' . $ e ->getTraceAsString ());
124131 $ this ->detach ($ processor );
125132 }
126133
@@ -138,12 +145,12 @@ private function formatMessage(object|string $message, array $params = []): stri
138145 foreach ($ params as $ k => $ v ) {
139146 $ replacements ['{ ' . $ k . '} ' ] = $ v ;
140147 }
141- return \ strtr ((string )$ message , $ replacements );
148+ return strtr ((string )$ message , $ replacements );
142149 }
143150
144151 private function now (): string
145152 {
146- return \ date_create_immutable ('now ' , $ this ->timezone )
153+ return date_create_immutable ('now ' , $ this ->timezone )
147154 ->format ($ this ->dateformat );
148155 }
149156}
0 commit comments