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

eliashaeussler / typo3-warming / 11203702983

06 Oct 2024 05:09PM UTC coverage: 91.333% (+0.05%) from 91.282%
11203702983

push

github

web-flow
Merge pull request #711 from eliashaeussler/feature/cache-warmup-v3

[!!!][FEATURE] Upgrade to `eliashaeussler/cache-warmup` v3

31 of 33 new or added lines in 7 files covered. (93.94%)

2 existing lines in 1 file now uncovered.

1096 of 1200 relevant lines covered (91.33%)

8.47 hits per line

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

86.67
/Classes/Crawler/LoggingCrawlerTrait.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of the TYPO3 CMS extension "warming".
7
 *
8
 * Copyright (C) 2021-2024 Elias Häußler <elias@haeussler.dev>
9
 *
10
 * This program is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU General Public License as published by
12
 * the Free Software Foundation, either version 2 of the License, or
13
 * (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22
 */
23

24
namespace EliasHaeussler\Typo3Warming\Crawler;
25

26
use EliasHaeussler\CacheWarmup;
27
use EliasHaeussler\SSE;
28
use Psr\Log;
29
use TYPO3\CMS\Core;
30

31
/**
32
 * LoggingCrawlerTrait
33
 *
34
 * @author Elias Häußler <elias@haeussler.dev>
35
 * @license GPL-2.0-or-later
36
 */
37
trait LoggingCrawlerTrait
38
{
39
    private ?Log\LoggerInterface $logger = null;
40

41
    private function createLogHandler(): CacheWarmup\Http\Message\Handler\LogHandler
13✔
42
    {
43
        $logger = $this->logger;
13✔
44

45
        if ($logger === null) {
13✔
46
            $logger = $this->createLogger();
7✔
47
        }
48

49
        // We use lowest log level because logger minimum log level is handled by the logger itself
50
        return new CacheWarmup\Http\Message\Handler\LogHandler($logger, Log\LogLevel::DEBUG);
13✔
51
    }
52

53
    private function createLogger(): Log\LoggerInterface
7✔
54
    {
55
        if ($this instanceof StreamableCrawler && $this->stream instanceof SSE\Stream\SelfEmittingEventStream) {
7✔
UNCOV
56
            $requestId = $this->stream->getId();
×
57
            // We avoid calling GeneralUtility::makeInstance() here
58
            // since LogManager is a singleton and we would not be
59
            // able to create a new instance of it.
UNCOV
60
            $logManager = new Core\Log\LogManager($requestId);
×
61
        } else {
62
            $logManager = Core\Utility\GeneralUtility::makeInstance(Core\Log\LogManager::class);
7✔
63
        }
64

65
        return $logManager->getLogger(static::class);
7✔
66
    }
67

68
    public function setLogger(Log\LoggerInterface $logger): void
6✔
69
    {
70
        $this->logger = $logger;
6✔
71
    }
72

73
    public function setLogLevel(string $logLevel): void
4✔
74
    {
75
        // Intentionally left blank. Log level is handled by the configured logger itself.
76
    }
4✔
77
}
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