• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

miaoxing / services / 6785744892

04 Nov 2023 03:34PM UTC coverage: 11.327%. Remained the same
6785744892

push

github

twinh
fix(Logger): PHP 8.1 Deprecated:  Implicit conversion from float to int loses precision

0 of 1 new or added line in 1 file covered. (0.0%)

70 of 618 relevant lines covered (11.33%)

6.56 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Service/Logger.php
1
<?php
2

3
namespace Miaoxing\Services\Service;
4

5
/**
6
 * @property Logger $errorLogger
7
 */
8
class Logger extends \Wei\Logger
9
{
10
    /**
11
     * @var string
12
     */
13
    protected $dir = 'storage/logs';
14

15
    /**
16
     * @var string
17
     */
18
    protected $dateFormat = 'Y-m-d H:i:s';
19

20
    /**
21
     * 引到 errorLogger 服务的最低级别
22
     *
23
     * @var string
24
     */
25
    protected $proxyLevel = 'info';
26

27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function __construct(array $options = [])
31
    {
32
        parent::__construct($options);
×
33

34
        // 创建默认的错误日志配置
35
        if (!$this->wei->getConfig('error:logger')) {
×
36
            $this->wei->setConfig('error:logger', [
×
37
                'dir' => $this->dir,
×
38
                'fileFormat' => '\e\r\r\o\r' . $this->fileFormat,
×
39
            ]);
40
        }
41
    }
42

43
    /**
44
     * {@inheritdoc}
45
     *
46
     * @param bool $fromErrorLogger 是否来自error.logger对象
47
     */
48
    public function log($level, $message, $context = [], $fromErrorLogger = false)
49
    {
50
        // 将较高级别的日志,引到 errorLogger 服务
51
        if ($fromErrorLogger || ($this->levels[$level] ?? 0) < $this->levels[$this->proxyLevel]) {
×
52
            return parent::log($level, $message, $context);
×
53
        } else {
54
            return $this->errorLogger->log($level, $message, $context, true);
×
55
        }
56
    }
57

58
    protected function formatLog($level, $message, $context = [])
59
    {
60
        // Format message and content
61
        if (!is_array($context)) {
×
62
            $context = ['context' => $context];
×
63
        }
64
        $params = $this->formatParams($message, $context + $this->context);
×
65

66
        $params = array_merge([
×
67
            'level' => strtoupper($level),
×
68
            'message' => $params['message'],
×
NEW
69
            'time' => date($this->dateFormat, time()),
×
70
            'channel' => $this->namespace,
×
71
        ], $params);
×
72

73
        return json_encode($params, \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE) . "\n";
×
74
    }
75
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc