Passed
Pull Request — master (#182)
by Arman
12:44 queued 09:39
created

LoggerConfig::getLogLevel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
/**
4
 * Quantum PHP Framework
5
 *
6
 * An open source software development framework for PHP
7
 *
8
 * @package Quantum
9
 * @author Arman Ag. <[email protected]>
10
 * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org)
11
 * @link http://quantum.softberg.org/
12
 * @since 2.9.5
13
 */
14
15
namespace Quantum\Logger;
16
17
/**
18
 * Class LoggerConfig
19
 * @package Quantum\Logger
20
 */
21
class LoggerConfig
22
{
23
    /**
24
     * Log levels mapped to integer values.
25
     */
26
    const LOG_LEVELS = [
27
        'debug' => 100,
28
        'info' => 200,
29
        'notice' => 250,
30
        'warning' => 300,
31
        'error' => 400,
32
        'critical' => 500,
33
        'alert' => 550,
34
        'emergency' => 600,
35
    ];
36
37
    /**
38
     * Default log level.
39
     */
40
    const DEFAULT_LOG_LEVEL = 'error';
41
42
    /**
43
     * @var string
44
     */
45
    private static $logLevel = self::DEFAULT_LOG_LEVEL;
46
47
    /**
48
     * Set the application's log level.
49
     * @param string $level
50
     * @return void
51
     */
52
    public static function setAppLogLevel(string $level): void
53
    {
54
        if (isset(self::LOG_LEVELS[$level])) {
55
            self::$logLevel = $level;
56
        }
57
    }
58
59
    /**
60
     * Get the integer value of the application's log level.
61
     * @return int
62
     */
63
    public static function getAppLogLevel(): int
64
    {
65
        return self::LOG_LEVELS[self::$logLevel] ?? self::LOG_LEVELS[self::DEFAULT_LOG_LEVEL];
66
    }
67
68
    /**
69
     * Get the integer log level for a given error type.
70
     * @param string $errorType
71
     * @return int
72
     */
73
    public static function getLogLevel(string $errorType): int
74
    {
75
        return self::LOG_LEVELS[$errorType] ?? self::LOG_LEVELS[self::DEFAULT_LOG_LEVEL];
76
    }
77
}
78