ArrayUtil.php
1 year ago
DefaultLogger.php
1 year ago
JsonSerializable.php
1 year ago
Logger.php
1 year ago
StringUtil.php
1 year ago
TimeUnit.php
1 year ago
TimeUtil.php
1 year ago
TimeValue.php
1 year ago
UrlUtil.php
1 year ago
DefaultLogger.php
31 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WonderPush\Util; |
| 4 | |
| 5 | if (count(get_included_files()) === 1) { http_response_code(403); exit(); } // Prevent direct access |
| 6 | |
| 7 | /** |
| 8 | * A logger that dumps to `error_log()`. |
| 9 | */ |
| 10 | class DefaultLogger implements Logger { |
| 11 | |
| 12 | public function log($level, $message, array $context = array()) { |
| 13 | if (!empty($context) && is_string($message)) { |
| 14 | $message = StringUtil::format($message, $context); |
| 15 | } |
| 16 | |
| 17 | if ($message instanceof \stdClass) { |
| 18 | if (defined('JSON_UNESCAPED_SLASHES')) { |
| 19 | // @codingStandardsIgnoreLine |
| 20 | $message = json_encode($message, JSON_UNESCAPED_SLASHES); |
| 21 | } else { |
| 22 | $message = json_encode($message); |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | /** @noinspection ForgottenDebugOutputInspection */ |
| 27 | error_log($message); |
| 28 | } |
| 29 | |
| 30 | } |
| 31 |