1
|
|
|
<?php |
2
|
|
|
namespace Log; |
3
|
|
|
require('vendor/autoload.php'); |
4
|
|
|
|
5
|
|
|
abstract class LogService extends \Psr\Log\AbstractLogger |
6
|
|
|
{ |
7
|
|
|
protected $logLevels = array( |
8
|
|
|
\Psr\Log\LogLevel::EMERGENCY, |
9
|
|
|
\Psr\Log\LogLevel::ALERT, |
10
|
|
|
\Psr\Log\LogLevel::CRITICAL, |
11
|
|
|
\Psr\Log\LogLevel::ERROR, |
12
|
|
|
\Psr\Log\LogLevel::WARNING, |
13
|
|
|
\Psr\Log\LogLevel::NOTICE); |
14
|
|
|
|
15
|
|
|
public function __construct($params=false) |
16
|
|
|
{ |
17
|
|
|
if(isset($params['defaultLogLevels'])) |
18
|
|
|
{ |
19
|
|
|
$this->logLevels = $params['defaultLogLevels']; |
20
|
|
|
} |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Interpolates context values into the message placeholders. |
25
|
|
|
*/ |
26
|
|
|
protected function interpolate($message, array $context = array()) |
27
|
|
|
{ |
28
|
|
|
// build a replacement array with braces around the context keys |
29
|
|
|
$replace = array(); |
30
|
|
|
foreach ($context as $key => $val) { |
31
|
|
|
// check that the value can be casted to string |
32
|
|
|
if (!is_array($val) && (!is_object($val) || method_exists($val, '__toString'))) { |
33
|
|
|
$replace['{' . $key . '}'] = $val; |
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
// interpolate replacement values into the message and return |
38
|
|
|
return strtr($message, $replace); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
protected function shouldLog($level) |
42
|
|
|
{ |
43
|
|
|
return in_array($level, $this->logLevels); |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
/* vim: set tabstop=4 shiftwidth=4 expandtab: */ |
47
|
|
|
|