Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Log;
4
 
5
use InvalidArgumentException;
6
use Monolog\Logger as Monolog;
7
 
8
trait ParsesLogConfiguration
9
{
10
    /**
11
     * The Log levels.
12
     *
13
     * @var array
14
     */
15
    protected $levels = [
16
        'debug' => Monolog::DEBUG,
17
        'info' => Monolog::INFO,
18
        'notice' => Monolog::NOTICE,
19
        'warning' => Monolog::WARNING,
20
        'error' => Monolog::ERROR,
21
        'critical' => Monolog::CRITICAL,
22
        'alert' => Monolog::ALERT,
23
        'emergency' => Monolog::EMERGENCY,
24
    ];
25
 
26
    /**
27
     * Get fallback log channel name.
28
     *
29
     * @return string
30
     */
31
    abstract protected function getFallbackChannelName();
32
 
33
    /**
34
     * Parse the string level into a Monolog constant.
35
     *
36
     * @param  array  $config
37
     * @return int
38
     *
39
     * @throws \InvalidArgumentException
40
     */
41
    protected function level(array $config)
42
    {
43
        $level = $config['level'] ?? 'debug';
44
 
45
        if (isset($this->levels[$level])) {
46
            return $this->levels[$level];
47
        }
48
 
49
        throw new InvalidArgumentException('Invalid log level.');
50
    }
51
 
52
    /**
53
     * Parse the action level from the given configuration.
54
     *
55
     * @param  array  $config
56
     * @return int
57
     */
58
    protected function actionLevel(array $config)
59
    {
60
        $level = $config['action_level'] ?? 'debug';
61
 
62
        if (isset($this->levels[$level])) {
63
            return $this->levels[$level];
64
        }
65
 
66
        throw new InvalidArgumentException('Invalid log action level.');
67
    }
68
 
69
    /**
70
     * Extract the log channel from the given configuration.
71
     *
72
     * @param  array  $config
73
     * @return string
74
     */
75
    protected function parseChannel(array $config)
76
    {
77
        return $config['name'] ?? $this->getFallbackChannelName();
78
    }
79
}