blob: dc340cdeef04b36827e93d94ae77ffc64c931f24 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
<?php
namespace SimpleLogger;
use Psr\Log\AbstractLogger;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
/**
* Handler for multiple loggers
*
* @package SimpleLogger
* @author Frédéric Guillot
*/
class Logger extends AbstractLogger implements LoggerAwareInterface
{
/**
* Logger instances
*
* @access private
*/
private $loggers = array();
/**
* Get level priority
*
* @param mixed $level
* @return integer
*/
public function getLevelPriority($level)
{
switch ($level) {
case LogLevel::EMERGENCY:
return 600;
case LogLevel::ALERT:
return 550;
case LogLevel::CRITICAL:
return 500;
case LogLevel::ERROR:
return 400;
case LogLevel::WARNING:
return 300;
case LogLevel::NOTICE:
return 250;
case LogLevel::INFO:
return 200;
}
return 100;
}
/**
* Sets a logger instance on the object
*
* @param LoggerInterface $logger
* @return null
*/
public function setLogger(LoggerInterface $logger)
{
$this->loggers[] = $logger;
}
/**
* Proxy method to the real loggers
*
* @param mixed $level
* @param string $message
* @param array $context
* @return null
*/
public function log($level, $message, array $context = array())
{
foreach ($this->loggers as $logger) {
if ($this->getLevelPriority($level) >= $this->getLevelPriority($logger->getLevel())) {
$logger->log($level, $message, $context);
}
}
}
/**
* Dump variables for debugging
*
* @param mixed $variable
*/
public function dump($variable)
{
foreach ($this->loggers as $logger) {
if ($this->getLevelPriority(LogLevel::DEBUG) >= $this->getLevelPriority($logger->getLevel())) {
$logger->dump($variable);
}
}
}
}
|