-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExtendedDataFormatter.php
57 lines (50 loc) · 1.66 KB
/
ExtendedDataFormatter.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
<?php
namespace phpWTL;
use phpWTL\aBasicDataFormatter;
require_once 'aBasicDataFormatter.php';
/**
* Data formatter for the extended log file format.
*
* @author Michael Beyer <mgbeyer@gmx.de>
* @version v0.2.0
* @api
*/
class ExtendedDataFormatter extends aBasicDataFormatter {
protected static $loggerContent= null;
protected static $fieldDescriptor= null;
/**
* @param object $loggerContent Provide a LoggerContent object. Also store the format blueprint via the LoggerContent object (which knows its FormatDescriptor).
*
* @author Michael Beyer <mgbeyer@gmx.de>
* @version v0.1.1
*/
protected function __construct($loggerContent= null) {
static::$loggerContent= $loggerContent;
if (static::$loggerContent) static::$fieldDescriptor= $loggerContent->getFormatDescriptor();
}
/**
* Format only a single log field and store it in the associated LoggerContent object.
*
* @param string $field_name ID of log format field.
* @param string $value Provide an (optional) value to format and pass thru to the LoggerContent object, so allowing for the injection of external data.
*
* @author Michael Beyer <mgbeyer@gmx.de>
* @version v0.1.2
* @api
*/
public function formatField($field_name, $value= null) {
if (static::$fieldDescriptor && static::$loggerContent) {
$format_string= static::$fieldDescriptor->getFormatter($field_name);
if (!$value) $value= static::$loggerContent->__get($field_name);
switch ($field_name) {
case "date":
case "time":
case "dir_start-date":
$value= strftime($format_string, $value);
break;
}
static::$loggerContent->__set($field_name, $value);
}
}
}
?>