"...external/git@labs.maarch.org:maarch/MaarchCourrier.git" did not exist on "d291246de7a936c46e5a19b67e17fa55c7b4b95d"
Newer
Older
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
<?php
/** Logger class
*
* @author Laurent Giovannoni <dev@maarch.org>
**/
class Logger4Php
{
/**
* Array of errors levels
*
* @protected
**/
protected $error_levels = array('DEBUG' => 0, 'INFO' => 1, 'NOTICE' => 2, 'WARNING' => 3, 'ERROR' => 4);
/**
* Maps each handler with its log threshold.
*
* @protected
**/
protected $mapping;
/**
* Minimum log level
*
* @protected
**/
protected $threshold_level;
/**
* Path to log4Php library
*
* @protected
**/
protected $log4PhpLibrary;
/**
* Name of the logger
*
* @protected
**/
protected $log4PhpLogger;
/**
* Name of the business code
*
* @protected
**/
protected $log4PhpBusinessCode;
/**
* Path of the param of log4php
*
* @protected
**/
protected $log4PhpConfigPath;
/**
* Name of the batch
*
* @protected
**/
protected $log4PhpBatchName;
/** Class constructor
*
* Inits the threshold level
*
* @param $threshold_level (string) Threshold level (set to 'INFO' by default)
**/
function __construct($threshold_level = 'WARNING')
{
$this->threshold_level = $threshold_level;
$this->mapping = array_fill(0, count($this->error_levels), array());
}
/** Writes error message in current handlers
*
* writes only if the error level is greater or equal the threshold level
*
* @param $msg (string) Error message
* @param $error_level (string) Error level (set to 'INFO' by default)
* @param $error_code (integer) Error code (set to 0 by default)
**/
public function write($msg, $error_level = 'INFO', $error_code = 0, $other_params = array())
{
if (!array_key_exists($error_level, $this->error_levels)) {
$error_level = 'INFO';
}
$foundLogger = false;
if ($this->error_levels[$error_level] >= $this->error_levels[$this->threshold_level]) {
for ($i=$this->error_levels[$error_level];$i>=0;$i--) {
foreach ($this->mapping[$i] as $handler) {
$handler->write($msg, $error_level, $error_code, $other_params);
if (
get_class($handler) == 'FileHandler'
&& (isset($this->log4PhpLibrary)
&& !empty($this->log4PhpLibrary))
) {
if ($error_code == 0) {
$result = 'OK';
} else {
$result = 'KO';
$msg = '%error_code:' . $error_code . '% ' . $msg;
}
require_once($this->log4PhpLibrary);
$remote_ip = '127.0.0.1';
Logger::configure($this->log4PhpConfigPath);
$logger = Logger::getLogger($this->log4PhpLogger);
$searchPatterns = array('%ACCESS_METHOD%',
'%RESULT%',
'%BUSINESS_CODE%',
'%HOW%',
'%WHAT%',
'%REMOTE_IP%',
'%BATCH_NAME%'
);
$replacePatterns = array('Script',
$result,
$this->log4PhpBusinessCode,
'UP',
$msg,
$remote_ip,
$this->log4PhpBatchName
);
$logLine = str_replace($searchPatterns,
$replacePatterns,
'[%ACCESS_METHOD%][%RESULT%]'
. '[%BUSINESS_CODE%][%HOW%][%WHAT%][%BATCH_NAME%]'
);
$this->writeLog4php($logger, $logLine, $error_level);
}
}
}
}
}
/**
*
* write a log entry with a specific log level
* @param object $logger Log4php logger
* @param string $logLine Line we want to trace
* @param enum $level Log level
*/
function writeLog4php($logger, $logLine, $level) {
switch ($level) {
case 'DEBUG':
$logger->debug($logLine);
break;
case 'INFO':
$logger->info($logLine);
break;
case 'WARNING':
$logger->warn($logLine);
break;
case 'ERROR':
$logger->error($logLine);
break;
case 'FATAL':
$logger->fatal($logLine);
break;
}
}
/** Adds a new handler in the current handlers array
*
* @param $handler (object) Handler object
**/
public function add_handler(&$handler, $error_level = NULL)
{
if(!isset($handler))
return false;
if(!isset($error_level) || !array_key_exists($error_level, $this->error_levels))
{
$error_level = $this->threshold_level;
}
$this->mapping[$this->error_levels[$error_level]][] = $handler;
return true;
}
/** Adds a new handler in the current handlers array
*
* @param $handler (object) Handler object
**/
public function change_handler_log_level(&$handler, $log_level )
{
if (!isset($handler) || !isset($log_level))
return false;
if (!array_key_exists($log_level, $this->error_levels)) {
return false;
}
for ($i=0; $i<count($this->mapping);$i++) {
for($j=0;$j<count($this->mapping[$i]);$j++) {
if($handler == $this->mapping[$i][$j]) {
unset($this->mapping[$i][$j]);
}
}
}
$this->mapping = array_values($this->mapping);
$this->mapping[$this->error_levels[$log_level]][] = $handler;
return true;
}
/** Sets treshold level
*
* @param $treshold (string) treshold level
**/
public function set_threshold_level($treshold)
{
if (isset($treshold) && array_key_exists($treshold, $this->error_levels)) {
$this->threshold_level = $treshold;
return true;
}
$this->threshold_level = 'WARNING';
return false;
}
/** Sets log4Php library path
*
* @param $log4PhpLibrary (string) path
**/
public function set_log4PhpLibrary($log4PhpLibrary)
{
if (isset($log4PhpLibrary) && !empty($log4PhpLibrary)) {
if (file_exists($log4PhpLibrary)) {
$this->log4PhpLibrary = $log4PhpLibrary;
return true;
} else {
return false;
}
}
return false;
}
/** Sets log4php logger name
*
* @param $log4PhpLogger (string) logger name
**/
public function set_log4PhpLogger($log4PhpLogger)
{
if (isset($log4PhpLogger) && !empty($log4PhpLogger)) {
$this->log4PhpLogger = $log4PhpLogger;
return true;
}
$this->log4PhpLogger = 'loggerTechnique';
return false;
}
/** Sets log4php path to log4php xml config
*
* @param $log4PhpPath (string) path to log4php xml config
**/
public function set_log4PhpConfigPath($log4PhpConfigPath)
{
if (isset($log4PhpConfigPath) && !empty($log4PhpConfigPath)) {
if (file_exists($log4PhpConfigPath)) {
$this->log4PhpConfigPath = $log4PhpConfigPath;
return true;
} else {
return false;
}
}
return false;
}
/** Sets log4php business code
*
* @param $log4PhpBusinessCode (string) business code
**/
public function set_log4PhpBusinessCode($log4PhpBusinessCode)
{
if (isset($log4PhpBusinessCode) && !empty($log4PhpBusinessCode)) {
$this->log4PhpBusinessCode = $log4PhpBusinessCode;
return true;
}
$this->log4PhpBusinessCode = 'Maarch';
return false;
}
/** Sets log4php batch name
*
* @param $log4PhpBatchName (string) BatchName
**/
public function set_log4PhpBatchName($log4PhpBatchName)
{
if (isset($log4PhpBatchName) && !empty($log4PhpBatchName)) {
$this->log4PhpBatchName = $log4PhpBatchName;
return true;
}
$this->log4PhpBatchName = 'MaarchBatch';
return false;
}
/** Class destructor
*
* Calls handlers destructors
**/
function __destruct()
{
for($i=0; $i<count($this->mapping);$i++)
{
foreach($this->mapping[$i] as $handler)
{
unset($handler);
}
}
}
}