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

tempestphp / tempest-framework / 14049246919

24 Mar 2025 09:42PM UTC coverage: 79.353% (-0.04%) from 79.391%
14049246919

push

github

web-flow
feat(support): support array parameters in string manipulations (#1073)

48 of 48 new or added lines in 2 files covered. (100.0%)

735 existing lines in 126 files now uncovered.

10492 of 13222 relevant lines covered (79.35%)

90.78 hits per line

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

70.45
/src/Tempest/Log/src/GenericLogger.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Tempest\Log;
6

7
use Monolog\Level as MonologLogLevel;
8
use Monolog\Logger as Monolog;
9
use Psr\Log\LogLevel as PsrLogLevel;
10
use Stringable;
11
use Tempest\EventBus\EventBus;
12

13
final class GenericLogger implements Logger
14
{
15
    /** @var array<int, Monolog> */
16
    private array $drivers = [];
17

18
    public function __construct(
40✔
19
        private readonly LogConfig $logConfig,
20
        private readonly EventBus $eventBus,
21
    ) {}
40✔
22

UNCOV
23
    public function emergency(Stringable|string $message, array $context = []): void
×
24
    {
UNCOV
25
        $this->log(LogLevel::EMERGENCY, $message, $context);
×
26
    }
27

UNCOV
28
    public function alert(Stringable|string $message, array $context = []): void
×
29
    {
UNCOV
30
        $this->log(LogLevel::ALERT, $message, $context);
×
31
    }
32

UNCOV
33
    public function critical(Stringable|string $message, array $context = []): void
×
34
    {
UNCOV
35
        $this->log(LogLevel::CRITICAL, $message, $context);
×
36
    }
37

UNCOV
38
    public function error(Stringable|string $message, array $context = []): void
×
39
    {
UNCOV
40
        $this->log(LogLevel::ERROR, $message, $context);
×
41
    }
42

UNCOV
43
    public function warning(Stringable|string $message, array $context = []): void
×
44
    {
UNCOV
45
        $this->log(LogLevel::WARNING, $message, $context);
×
46
    }
47

UNCOV
48
    public function notice(Stringable|string $message, array $context = []): void
×
49
    {
UNCOV
50
        $this->log(LogLevel::NOTICE, $message, $context);
×
51
    }
52

53
    public function info(Stringable|string $message, array $context = []): void
4✔
54
    {
55
        $this->log(LogLevel::INFO, $message, $context);
4✔
56
    }
57

58
    public function debug(Stringable|string $message, array $context = []): void
4✔
59
    {
60
        $this->log(LogLevel::DEBUG, $message, $context);
4✔
61
    }
62

63
    /** @param MonologLogLevel|LogLevel|string $level */
64
    public function log($level, Stringable|string $message, array $context = []): void
40✔
65
    {
66
        if (! ($level instanceof MonologLogLevel)) {
40✔
67
            $level = match ($level) {
32✔
68
                LogLevel::EMERGENCY, PsrLogLevel::EMERGENCY => MonologLogLevel::Emergency,
32✔
69
                LogLevel::ALERT, PsrLogLevel::ALERT => MonologLogLevel::Alert,
29✔
70
                LogLevel::CRITICAL, PsrLogLevel::CRITICAL => MonologLogLevel::Critical,
26✔
71
                LogLevel::ERROR, PsrLogLevel::ERROR => MonologLogLevel::Error,
23✔
72
                LogLevel::WARNING, PsrLogLevel::WARNING => MonologLogLevel::Warning,
20✔
73
                LogLevel::NOTICE, PsrLogLevel::NOTICE => MonologLogLevel::Notice,
17✔
74
                LogLevel::INFO, PsrLogLevel::INFO => MonologLogLevel::Info,
14✔
75
                LogLevel::DEBUG, PsrLogLevel::DEBUG => MonologLogLevel::Debug,
7✔
UNCOV
76
                default => MonologLogLevel::Info,
×
77
            };
32✔
78
        }
79

80
        $this->writeLog($level, $message, $context);
40✔
81

82
        $this->eventBus->dispatch(new MessageLogged(LogLevel::fromMonolog($level), $message, $context));
40✔
83
    }
84

85
    private function writeLog(MonologLogLevel $level, string $message, array $context): void
40✔
86
    {
87
        foreach ($this->logConfig->channels as $channel) {
40✔
88
            $this->resolveDriver($channel, $level)->log($level, $message, $context);
40✔
89
        }
90
    }
91

92
    private function resolveDriver(LogChannel $channel, MonologLogLevel $level): Monolog
40✔
93
    {
94
        if (! isset($this->drivers[spl_object_id($channel)])) {
40✔
95
            $this->drivers[spl_object_id($channel)] = new Monolog(
40✔
96
                name: $this->logConfig->prefix,
40✔
97
                handlers: $channel->getHandlers($level),
40✔
98
                processors: $channel->getProcessors(),
40✔
99
            );
40✔
100
        }
101

102
        return $this->drivers[spl_object_id($channel)];
40✔
103
    }
104
}
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