1
|
|
|
<?php |
2
|
|
|
namespace SimpleLogger; |
3
|
|
|
|
4
|
|
|
use Psr\Log\LogLevel; |
5
|
|
|
use SimpleLogger\LogLevelMap; |
6
|
|
|
|
7
|
|
|
class Configuration extends LogLevelMap |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* Log file name. |
11
|
|
|
* |
12
|
|
|
* @var string |
13
|
|
|
*/ |
14
|
|
|
public $logfile = null; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Default tag |
18
|
|
|
* |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
public $tag = null; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Default log level. |
25
|
|
|
* |
26
|
|
|
* @var int |
27
|
|
|
*/ |
28
|
|
|
public $verbosity = null; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Default log level (console). |
32
|
|
|
* |
33
|
|
|
* @var int |
34
|
|
|
*/ |
35
|
|
|
public $console_verbosity = null; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Console log line format. |
39
|
|
|
* |
40
|
|
|
* @var string |
41
|
|
|
*/ |
42
|
|
|
public $console_format = null; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* File log line format. |
46
|
|
|
* |
47
|
|
|
* @var string |
48
|
|
|
*/ |
49
|
|
|
public $file_format = null; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Sets log file name. |
53
|
|
|
* |
54
|
|
|
* @param string $logfile log file name |
55
|
|
|
* @return object |
56
|
|
|
*/ |
57
|
|
|
final public function setLogfile($logfile) |
58
|
|
|
{ |
59
|
|
|
$this->logfile = $logfile; |
60
|
|
|
return $this; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Sets log line tag. |
65
|
|
|
* |
66
|
|
|
* @param string $tag tag |
67
|
|
|
* @return object |
68
|
|
|
*/ |
69
|
|
|
final public function setTag($tag) |
70
|
|
|
{ |
71
|
|
|
$this->tag = $tag; |
72
|
|
|
return $this; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Sets log level verbosity. |
77
|
|
|
* |
78
|
|
|
* @param int $verbosity log verbosity |
79
|
|
|
* @return object |
80
|
|
|
*/ |
81
|
|
|
final public function setVerbosity($verbosity) |
82
|
|
|
{ |
83
|
|
|
$this->verbosity = $this->getLevel($verbosity); |
84
|
|
|
return $this; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Sets log level verbosity. |
89
|
|
|
* |
90
|
|
|
* @param int $verbosity log verbosity |
91
|
|
|
* @return object |
92
|
|
|
*/ |
93
|
|
|
final public function setConsoleVerbosity($verbosity) |
94
|
|
|
{ |
95
|
|
|
$this->console_verbosity = $this->getLevel($verbosity); |
96
|
|
|
return $this; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Sets console log line format. |
101
|
|
|
* |
102
|
|
|
* @param int $format log line format |
103
|
|
|
* @return object |
104
|
|
|
*/ |
105
|
|
|
final public function setLoggerConsoleFormat($format) |
106
|
|
|
{ |
107
|
|
|
$this->console_format = $format; |
108
|
|
|
return $this; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Sets file log line format. |
113
|
|
|
* |
114
|
|
|
* @param int $format log line format |
115
|
|
|
* @return object |
116
|
|
|
*/ |
117
|
|
|
final public function setLoggerFileFormat($format) |
118
|
|
|
{ |
119
|
|
|
$this->file_format = $format; |
120
|
|
|
return $this; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Gets log file name. |
125
|
|
|
* |
126
|
|
|
* @return string |
127
|
|
|
*/ |
128
|
|
|
final public function getLogfile() |
129
|
|
|
{ |
130
|
|
|
return $this->logfile; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Gets tag |
135
|
|
|
* |
136
|
|
|
* @return string |
137
|
|
|
*/ |
138
|
|
|
final public function getTag() |
139
|
|
|
{ |
140
|
|
|
if ($this->tag === null) |
|
|
|
|
141
|
|
|
{ |
142
|
|
|
$this->tag = 'NA'; |
143
|
|
|
} |
144
|
|
|
return $this->tag; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Gets log level verbosity. |
149
|
|
|
* |
150
|
|
|
* @return string |
151
|
|
|
*/ |
152
|
|
|
final public function getVerbosity() |
153
|
|
|
{ |
154
|
|
|
if ($this->verbosity === null) |
|
|
|
|
155
|
|
|
{ |
156
|
|
|
$this->verbosity = $this->getLevel(LogLevel::DEBUG); |
157
|
|
|
} |
158
|
|
|
return $this->verbosity; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* Gets log level verbosity. |
163
|
|
|
* |
164
|
|
|
* @return string |
165
|
|
|
*/ |
166
|
|
|
final public function getConsoleVerbosity() |
167
|
|
|
{ |
168
|
|
|
if ($this->console_verbosity === null) |
|
|
|
|
169
|
|
|
{ |
170
|
|
|
$this->console_verbosity = $this->getLevel(LogLevel::DEBUG); |
171
|
|
|
} |
172
|
|
|
return $this->console_verbosity; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* Gets log line format. |
177
|
|
|
* |
178
|
|
|
* @return string |
179
|
|
|
*/ |
180
|
|
|
final public function getLoggerConsoleFormat() |
181
|
|
|
{ |
182
|
|
|
if ($this->console_format === null) |
|
|
|
|
183
|
|
|
{ |
184
|
|
|
$this->console_format = "%t %l %c:%f - %m"; |
185
|
|
|
} |
186
|
|
|
return $this->console_format; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* Gets log line format. |
191
|
|
|
* |
192
|
|
|
* @return string |
193
|
|
|
*/ |
194
|
|
|
final public function getLoggerFileFormat() |
195
|
|
|
{ |
196
|
|
|
if ($this->file_format === null) |
|
|
|
|
197
|
|
|
{ |
198
|
|
|
$this->file_format = "%t [%l] {%c:%f:%L} %p - %m"; |
199
|
|
|
} |
200
|
|
|
return $this->file_format; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* {@inheritdoc} |
205
|
|
|
*/ |
206
|
|
|
final public function getLevel($log_level) |
207
|
|
|
{ |
208
|
|
|
return self::$LEVEL_MAP[$log_level]; |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* {@inheritdoc} |
213
|
|
|
*/ |
214
|
|
|
final public function getColours($log_level) |
215
|
|
|
{ |
216
|
|
|
return self::$LEVEL_COLOUR_MAP[$log_level]; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
} |
220
|
|
|
|