Skip to content

Commit ef42623

Browse files
author
Wazabii
committed
Semantical improvements
1 parent 99ac733 commit ef42623

3 files changed

Lines changed: 25 additions & 10 deletions

File tree

Handlers/ErrorLogHandler.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
namespace MaplePHP\Log\Handlers;
44

5-
use MaplePHP\Http\Interfaces\StreamInterface;
6-
use MaplePHP\Http\Stream;
7-
85
class ErrorLogHandler extends AbstractHandler
96
{
107
public function __construct(?string $file = null)
@@ -16,15 +13,17 @@ public function __construct(?string $file = null)
1613
}
1714

1815
/**
19-
* Apache/server error log handler
16+
* Take over the servers error log handler
2017
* @param string $level
2118
* @param string $message
22-
* @param string $date
19+
* @param array $context
20+
* @param string $date (Only a placeholder right now, date is handled automatically by error_log)
2321
* @return void
2422
*/
2523
public function handler(string $level, string $message, array $context, string $date): void
2624
{
27-
$message = sprintf($message, json_encode($context));
28-
error_log("[{$level}] {$message}");
25+
$encode = json_encode($context);
26+
$message = sprintf($message, $encode);
27+
error_log("[{$level}] {$message} {$encode}");
2928
}
3029
}

Handlers/StreamHandler.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,17 @@ public function __construct(string $file, ?int $size = null, ?int $count = null)
2929
* Stream handler
3030
* @param string $level
3131
* @param string $message
32+
* @param array $context
3233
* @param string $date
3334
* @return void
3435
*/
3536
public function handler(string $level, string $message, array $context, string $date): void
3637
{
37-
$message = sprintf($message, json_encode($context));
38-
38+
$encode = json_encode($context);
39+
$message = sprintf($message, $encode);
3940
$this->rotate();
4041
$this->stream()->seek(0);
41-
$this->stream()->write("{$date} [{$level}] {$message}");
42+
$this->stream()->write("[{$date}] [{$level}] {$message} {$encode}");
4243
$this->stream()->write("\n");
4344
}
4445

Logger.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,21 @@ public function log(mixed $level, string|\Stringable $message, array $context =
4848
);
4949
}
5050

51+
public function getLevel(): mixed
52+
{
53+
return $this->level;
54+
}
55+
56+
public function getMessage(): string
57+
{
58+
return (string)$this->message;
59+
}
60+
61+
public function getContext(): array
62+
{
63+
return $this->context;
64+
}
65+
5166
/**
5267
* Get formated date
5368
* @return string

0 commit comments

Comments
 (0)