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

codeigniter4 / CodeIgniter4 / 8677009716

13 Apr 2024 11:45PM UTC coverage: 84.44% (-2.2%) from 86.607%
8677009716

push

github

web-flow
Merge pull request #8776 from kenjis/fix-findQualifiedNameFromPath-Cannot-declare-class-v3

fix: Cannot declare class CodeIgniter\Config\Services, because the name is already in use

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

478 existing lines in 72 files now uncovered.

20318 of 24062 relevant lines covered (84.44%)

188.23 hits per line

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

87.5
/system/Log/Handlers/ErrorlogHandler.php
1
<?php
2

3
declare(strict_types=1);
4

5
/**
6
 * This file is part of CodeIgniter 4 framework.
7
 *
8
 * (c) CodeIgniter Foundation <admin@codeigniter.com>
9
 *
10
 * For the full copyright and license information, please view
11
 * the LICENSE file that was distributed with this source code.
12
 */
13

14
namespace CodeIgniter\Log\Handlers;
15

16
use CodeIgniter\Log\Exceptions\LogException;
17

18
/**
19
 * Log handler that writes to PHP's `error_log()`
20
 *
21
 * @see \CodeIgniter\Log\Handlers\ErrorlogHandlerTest
22
 */
23
class ErrorlogHandler extends BaseHandler
24
{
25
    /**
26
     * Message is sent to PHP's system logger, using the Operating System's
27
     * system logging mechanism or a file, depending on what the error_log
28
     * configuration directive is set to.
29
     */
30
    public const TYPE_OS = 0;
31

32
    /**
33
     * Message is sent directly to the SAPI logging handler.
34
     */
35
    public const TYPE_SAPI = 4;
36

37
    /**
38
     * Says where the error should go. Currently supported are
39
     * 0 (`TYPE_OS`) and 4 (`TYPE_SAPI`).
40
     *
41
     * @var int
42
     */
43
    protected $messageType = 0;
44

45
    /**
46
     * Constructor.
47
     *
48
     * @param list<mixed> $config
49
     */
50
    public function __construct(array $config = [])
51
    {
52
        parent::__construct($config);
2✔
53

54
        $messageType = $config['messageType'] ?? self::TYPE_OS;
2✔
55

56
        if (! is_int($messageType) || ! in_array($messageType, [self::TYPE_OS, self::TYPE_SAPI], true)) {
2✔
57
            throw LogException::forInvalidMessageType(print_r($messageType, true));
1✔
58
        }
59

60
        $this->messageType = $messageType;
1✔
61
    }
62

63
    /**
64
     * Handles logging the message.
65
     * If the handler returns false, then execution of handlers
66
     * will stop. Any handlers that have not run, yet, will not
67
     * be run.
68
     *
69
     * @param string $level
70
     * @param string $message
71
     */
72
    public function handle($level, $message): bool
73
    {
74
        $message = strtoupper($level) . ' --> ' . $message . "\n";
1✔
75

76
        return $this->errorLog($message, $this->messageType);
1✔
77
    }
78

79
    /**
80
     * Extracted call to `error_log()` in order to be tested.
81
     *
82
     * @codeCoverageIgnore
83
     */
84
    protected function errorLog(string $message, int $messageType): bool
85
    {
UNCOV
86
        return error_log($message, $messageType);
×
87
    }
88
}
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

© 2026 Coveralls, Inc