Completed
Push — master ( 6c5d6a...127e8d )
by Oleg
03:38
created

Logger   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 63
wmc 8
lcom 1
cbo 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 14 5
A send() 0 9 3
1
<?php /** MicroLogger */
2
3
namespace Micro\Logger\Driver;
4
5
use Micro\Logger\Adapter;
6
7
/**
8
 * Logger manager
9
 *
10
 * @author Oleg Lunegov <[email protected]>
11
 * @link https://github.com/linpax/microphp-framework
12
 * @copyright Copyright (c) 2013 Oleg Lunegov
13
 * @license https://github.com/linpax/microphp-framework/blob/master/LICENSE
14
 * @package Micro
15
 * @subpackage Logger
16
 * @version 1.0
17
 * @since 1.0
18
 */
19
class Logger
20
{
21
    /** @var array $supportedLevels supported logger levels */
22
    public static $supportedLevels = [
23
        'emergency',
24
        'alert',
25
        'critical',
26
        'error',
27
        'warning',
28
        'notice',
29
        'info',
30
        'debug'
31
    ];
32
33
    /** @var Adapter[] $loggers defined loggers */
34
    protected $loggers = array();
35
36
37
    /**
38
     * Export loggers
39
     *
40
     * @access public
41
     *
42
     * @param array $loggers
43
     *
44
     * @result void
45
     */
46
    public function __construct(array $loggers = [])
47
    {
48
        foreach ($loggers AS $name => $log) {
49
            if (empty($log['class']) || !class_exists($log['class'])) {
50
                continue;
51
            }
52
53
            if (empty($log['levels'])) {
54
                continue;
55
            }
56
57
            $this->loggers[$name] = new $log['class']($log);
58
        }
59
    }
60
61
    /**
62
     * Send message to loggers
63
     *
64
     * @access public
65
     *
66
     * @param string $level logger level
67
     * @param string $message message to write
68
     *
69
     * @result void
70
     * @throws \Micro\Base\Exception
71
     */
72
    public function send($level, $message)
73
    {
74
        foreach ($this->loggers AS $log) {
75
            /** @var Adapter $log logger */
76
            if ($log->isSupportedLevel($level)) {
77
                $log->sendMessage($level, $message);
78
            }
79
        }
80
    }
81
}
82