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

Cecilapp / Cecil / 5046064611

pending completion
5046064611

push

github

GitHub
perf: native_function_invocation (#1697)

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

2784 of 4121 relevant lines covered (67.56%)

0.68 hits per line

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

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

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of Cecil.
7
 *
8
 * Copyright (c) Arnaud Ligny <arnaud@ligny.fr>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13

14
namespace Cecil\Logger;
15

16
use Psr\Log\InvalidArgumentException;
17
use Psr\Log\LogLevel;
18
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
19
use Symfony\Component\Console\Output\OutputInterface;
20

21
class ConsoleLogger extends PrintLogger
22
{
23
    public const ERROR = 'error';
24
    public const WARNING = 'comment';
25
    public const NOTICE = 'info';
26
    public const INFO = 'text';
27
    public const DEBUG = 'debug';
28

29
    protected $output;
30

31
    protected $verbosityLevelMap = [
32
        LogLevel::EMERGENCY => OutputInterface::VERBOSITY_NORMAL,
33
        LogLevel::ALERT     => OutputInterface::VERBOSITY_NORMAL,
34
        LogLevel::CRITICAL  => OutputInterface::VERBOSITY_NORMAL,
35
        LogLevel::ERROR     => OutputInterface::VERBOSITY_NORMAL,
36
        LogLevel::WARNING   => OutputInterface::VERBOSITY_VERY_VERBOSE,
37
        LogLevel::NOTICE    => OutputInterface::VERBOSITY_VERBOSE,
38
        LogLevel::INFO      => OutputInterface::VERBOSITY_VERY_VERBOSE,
39
        LogLevel::DEBUG     => OutputInterface::VERBOSITY_DEBUG,
40
    ];
41

42
    protected $formatLevelMap = [
43
        LogLevel::EMERGENCY => self::ERROR,
44
        LogLevel::ALERT     => self::ERROR,
45
        LogLevel::CRITICAL  => self::ERROR,
46
        LogLevel::ERROR     => self::ERROR,
47
        LogLevel::WARNING   => self::WARNING,
48
        LogLevel::NOTICE    => self::NOTICE,
49
        LogLevel::INFO      => self::INFO,
50
        LogLevel::DEBUG     => self::DEBUG,
51
    ];
52

53
    public function __construct(OutputInterface $output, array $verbosityLevelMap = [], array $formatLevelMap = [])
54
    {
55
        $this->output = $output;
×
56
        $this->verbosityLevelMap = $verbosityLevelMap + $this->verbosityLevelMap;
×
57
        $this->formatLevelMap = $formatLevelMap + $this->formatLevelMap;
×
58
    }
59

60
    /**
61
     * {@inheritdoc}
62
     *
63
     * @return void
64
     */
65
    public function log($level, $message, array $context = [])
66
    {
67
        $output = $this->output;
×
68
        $output->getFormatter()->setStyle('text', new OutputFormatterStyle('white'));
×
69
        $output->getFormatter()->setStyle('debug', new OutputFormatterStyle('blue', 'yellow'));
×
70

71
        if (!isset($this->verbosityLevelMap[$level])) {
×
72
            throw new InvalidArgumentException(sprintf('The log level "%s" does not exist.', $level));
×
73
        }
74

75
        // default pattern: <level>message</level>
76
        $pattern = '<%1$s>%2$s%3$s</%1$s>';
×
77
        $prefix = '';
×
78

79
        // steps prefix
80
        if (isset($context['step'])) {
×
81
            $prefix = sprintf('%s. ', $this->padPrefix((string) $context['step'][0], (string) $context['step'][1]));
×
82
        }
83

84
        // sub steps progress
85
        if (isset($context['progress'])) {
×
86
            // prefix
87
            $prefix = sprintf(
×
88
                '[%s/%s] ',
×
89
                $this->padPrefix((string) $context['progress'][0], (string) $context['progress'][1]),
×
90
                $context['progress'][1]
×
91
            );
×
92
        }
93

94
        $output->writeln(
×
95
            sprintf($pattern, $this->formatLevelMap[$level], $prefix, $this->interpolate($message, $context)),
×
96
            $this->verbosityLevelMap[$level]
×
97
        );
×
98
    }
99

100
    /**
101
     * Prefix padding.
102
     */
103
    private function padPrefix(string $prefix, string $max): string
104
    {
105
        return str_pad($prefix, \strlen($max), ' ', STR_PAD_LEFT);
×
106
    }
107
}
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