1: <?php
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: class LoggerLayoutPattern extends LoggerLayout {
34:
35:
36: const DEFAULT_CONVERSION_PATTERN = '%date %-5level %logger %message%newline';
37:
38:
39: const TTCC_CONVERSION_PATTERN = '%d [%t] %p %c %x - %m%n';
40:
41:
42: protected $pattern = self::DEFAULT_CONVERSION_PATTERN;
43:
44:
45: protected static $defaultConverterMap = array(
46: 'c' => 'LoggerPatternConverterLogger',
47: 'lo' => 'LoggerPatternConverterLogger',
48: 'logger' => 'LoggerPatternConverterLogger',
49:
50: 'C' => 'LoggerPatternConverterClass',
51: 'class' => 'LoggerPatternConverterClass',
52:
53: 'cookie' => 'LoggerPatternConverterCookie',
54:
55: 'd' => 'LoggerPatternConverterDate',
56: 'date' => 'LoggerPatternConverterDate',
57:
58: 'e' => 'LoggerPatternConverterEnvironment',
59: 'env' => 'LoggerPatternConverterEnvironment',
60:
61: 'ex' => 'LoggerPatternConverterThrowable',
62: 'exception' => 'LoggerPatternConverterThrowable',
63: 'throwable' => 'LoggerPatternConverterThrowable',
64:
65: 'F' => 'LoggerPatternConverterFile',
66: 'file' => 'LoggerPatternConverterFile',
67:
68: 'l' => 'LoggerPatternConverterLocation',
69: 'location' => 'LoggerPatternConverterLocation',
70:
71: 'L' => 'LoggerPatternConverterLine',
72: 'line' => 'LoggerPatternConverterLine',
73:
74: 'm' => 'LoggerPatternConverterMessage',
75: 'msg' => 'LoggerPatternConverterMessage',
76: 'message' => 'LoggerPatternConverterMessage',
77:
78: 'M' => 'LoggerPatternConverterMethod',
79: 'method' => 'LoggerPatternConverterMethod',
80:
81: 'n' => 'LoggerPatternConverterNewLine',
82: 'newline' => 'LoggerPatternConverterNewLine',
83:
84: 'p' => 'LoggerPatternConverterLevel',
85: 'le' => 'LoggerPatternConverterLevel',
86: 'level' => 'LoggerPatternConverterLevel',
87:
88: 'r' => 'LoggerPatternConverterRelative',
89: 'relative' => 'LoggerPatternConverterRelative',
90:
91: 'req' => 'LoggerPatternConverterRequest',
92: 'request' => 'LoggerPatternConverterRequest',
93:
94: 's' => 'LoggerPatternConverterServer',
95: 'server' => 'LoggerPatternConverterServer',
96:
97: 'ses' => 'LoggerPatternConverterSession',
98: 'session' => 'LoggerPatternConverterSession',
99:
100: 'sid' => 'LoggerPatternConverterSessionID',
101: 'sessionid' => 'LoggerPatternConverterSessionID',
102:
103: 't' => 'LoggerPatternConverterProcess',
104: 'pid' => 'LoggerPatternConverterProcess',
105: 'process' => 'LoggerPatternConverterProcess',
106:
107: 'x' => 'LoggerPatternConverterNDC',
108: 'ndc' => 'LoggerPatternConverterNDC',
109:
110: 'X' => 'LoggerPatternConverterMDC',
111: 'mdc' => 'LoggerPatternConverterMDC',
112: );
113:
114:
115: protected $converterMap = array();
116:
117: 118: 119: 120:
121: private $head;
122:
123:
124: public static function getDefaultConverterMap() {
125: return self::$defaultConverterMap;
126: }
127:
128:
129: public function __construct() {
130: $this->converterMap = self::$defaultConverterMap;
131: }
132:
133: 134: 135: 136: 137: 138:
139: public function setConversionPattern($conversionPattern) {
140: $this->pattern = $conversionPattern;
141: }
142:
143: 144: 145: 146:
147: public function activateOptions() {
148: if (!isset($this->pattern)) {
149: throw new LoggerException("Mandatory parameter 'conversionPattern' is not set.");
150: }
151:
152: $parser = new LoggerPatternParser($this->pattern, $this->converterMap);
153: $this->head = $parser->parse();
154: }
155:
156: 157: 158: 159: 160: 161:
162: public function format(LoggerLoggingEvent $event) {
163: $sbuf = '';
164: $converter = $this->head;
165: while ($converter !== null) {
166: $converter->format($sbuf, $event);
167: $converter = $converter->next;
168: }
169: return $sbuf;
170: }
171: }