-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAbstractLogger.php
88 lines (78 loc) · 2.04 KB
/
AbstractLogger.php
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
<?php
/**
* AttwFramework
*
* @author Gabriel Jacinto <[email protected]>
* @license MIT License
* @link http://attwframework.github.io
*/
namespace Attw\Logger;
use Attw\Logger\LoggerInterface;
/**
* Interface to logger
*/
abstract class AbstractLogger implements LoggerInterface
{
/**
* Types of logs
*
* @var array
*/
public static $types = array(
'emergency' => LOG_EMERG,
'alert' => LOG_ALERT,
'critical' => LOG_CRIT,
'error' => LOG_ERR,
'warning' => LOG_WARNING,
'notice' => LOG_NOTICE,
'info' => LOG_INFO,
'debug' => LOG_DEBUG
);
/**
* Customized camps of log
*
* @var array
*/
protected static $customizedCamps = array();
/**
* Log structure
*
* @var string
*/
protected static $logStructure = '[:type|:date] :message';
/**
* Set log structure
* The camps must have as first caracter ":" (without quotes)
*
* @param string $logStructure
*/
public static function setLogStructure($logStructure)
{
self::$logStructure = (string) $logStructure;
}
/**
* Attach a customized camps on log
*
* @param array|string $camp If be array, be the association
* if is string, require the second param
* @param string $value
*/
public static function addCustomizedCamp($camp, $value = null)
{
if (is_array($camp)) {
self::$customizedCamps = $camp;
} else {
if (is_string($camp) && is_null($value)) {
throw new UnexpectedValueException('If the first param is string, the second must not be null');
}
self::$customizedCamps[ $camp ] = $value;
}
foreach (self::$customizedCamps as $camp => $value) {
unset(self::$customizedCamps[ $camp ]);
if (substr($camp, 0, 1) != ':') {
$camp = ':' . $camp;
}
self::$customizedCamps[ print_r($camp, true) ] = print_r($value, true);
}
}
}