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

tempestphp / tempest-framework / 14024978163

23 Mar 2025 05:55PM UTC coverage: 79.391% (-0.05%) from 79.441%
14024978163

push

github

web-flow
feat(view): cache Blade and Twig templates in internal storage (#1061)

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

912 existing lines in 110 files now uncovered.

10478 of 13198 relevant lines covered (79.39%)

91.09 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
    ) {
22
    }
40✔
23

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

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

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

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

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

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

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

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

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

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

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

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

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

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