ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
Monolog\Formatter\LogstashFormatterTest Class Reference
+ Inheritance diagram for Monolog\Formatter\LogstashFormatterTest:
+ Collaboration diagram for Monolog\Formatter\LogstashFormatterTest:

Public Member Functions

 testDefaultFormatter ()
 @covers Monolog\Formatter\LogstashFormatter::format More...
 
 testFormatWithFileAndLine ()
 @covers Monolog\Formatter\LogstashFormatter::format More...
 
 testFormatWithContext ()
 @covers Monolog\Formatter\LogstashFormatter::format More...
 
 testFormatWithExtra ()
 @covers Monolog\Formatter\LogstashFormatter::format More...
 
 testFormatWithApplicationName ()
 
 testDefaultFormatterV1 ()
 @covers Monolog\Formatter\LogstashFormatter::format More...
 
 testFormatWithFileAndLineV1 ()
 @covers Monolog\Formatter\LogstashFormatter::format More...
 
 testFormatWithContextV1 ()
 @covers Monolog\Formatter\LogstashFormatter::format More...
 
 testFormatWithExtraV1 ()
 @covers Monolog\Formatter\LogstashFormatter::format More...
 
 testFormatWithApplicationNameV1 ()
 

Detailed Description

Definition at line 16 of file LogstashFormatterTest.php.

Member Function Documentation

◆ testDefaultFormatter()

Monolog\Formatter\LogstashFormatterTest::testDefaultFormatter ( )

@covers Monolog\Formatter\LogstashFormatter::format

Definition at line 21 of file LogstashFormatterTest.php.

22 {
23 $formatter = new LogstashFormatter('test', 'hostname');
24 $record = array(
25 'level' => Logger::ERROR,
26 'level_name' => 'ERROR',
27 'channel' => 'meh',
28 'context' => array(),
29 'datetime' => new \DateTime("@0"),
30 'extra' => array(),
31 'message' => 'log',
32 );
33
34 $message = json_decode($formatter->format($record), true);
35
36 $this->assertEquals("1970-01-01T00:00:00.000000+00:00", $message['@timestamp']);
37 $this->assertEquals('log', $message['@message']);
38 $this->assertEquals('meh', $message['@fields']['channel']);
39 $this->assertContains('meh', $message['@tags']);
40 $this->assertEquals(Logger::ERROR, $message['@fields']['level']);
41 $this->assertEquals('test', $message['@type']);
42 $this->assertEquals('hostname', $message['@source']);
43
44 $formatter = new LogstashFormatter('mysystem');
45
46 $message = json_decode($formatter->format($record), true);
47
48 $this->assertEquals('mysystem', $message['@type']);
49 }
const ERROR
Runtime errors.
Definition: Logger.php:57

References Monolog\Logger\ERROR.

◆ testDefaultFormatterV1()

Monolog\Formatter\LogstashFormatterTest::testDefaultFormatterV1 ( )

@covers Monolog\Formatter\LogstashFormatter::format

Definition at line 161 of file LogstashFormatterTest.php.

162 {
163 $formatter = new LogstashFormatter('test', 'hostname', null, 'ctxt_', LogstashFormatter::V1);
164 $record = array(
165 'level' => Logger::ERROR,
166 'level_name' => 'ERROR',
167 'channel' => 'meh',
168 'context' => array(),
169 'datetime' => new \DateTime("@0"),
170 'extra' => array(),
171 'message' => 'log',
172 );
173
174 $message = json_decode($formatter->format($record), true);
175
176 $this->assertEquals("1970-01-01T00:00:00.000000+00:00", $message['@timestamp']);
177 $this->assertEquals("1", $message['@version']);
178 $this->assertEquals('log', $message['message']);
179 $this->assertEquals('meh', $message['channel']);
180 $this->assertEquals('ERROR', $message['level']);
181 $this->assertEquals('test', $message['type']);
182 $this->assertEquals('hostname', $message['host']);
183
184 $formatter = new LogstashFormatter('mysystem', null, null, 'ctxt_', LogstashFormatter::V1);
185
186 $message = json_decode($formatter->format($record), true);
187
188 $this->assertEquals('mysystem', $message['type']);
189 }

References Monolog\Logger\ERROR, and Monolog\Formatter\LogstashFormatter\V1.

◆ testFormatWithApplicationName()

Monolog\Formatter\LogstashFormatterTest::testFormatWithApplicationName ( )

Definition at line 139 of file LogstashFormatterTest.php.

140 {
141 $formatter = new LogstashFormatter('app', 'test');
142 $record = array(
143 'level' => Logger::ERROR,
144 'level_name' => 'ERROR',
145 'channel' => 'meh',
146 'context' => array('from' => 'logger'),
147 'datetime' => new \DateTime("@0"),
148 'extra' => array('key' => 'pair'),
149 'message' => 'log'
150 );
151
152 $message = json_decode($formatter->format($record), true);
153
154 $this->assertArrayHasKey('@type', $message);
155 $this->assertEquals('app', $message['@type']);
156 }

References Monolog\Logger\ERROR.

◆ testFormatWithApplicationNameV1()

Monolog\Formatter\LogstashFormatterTest::testFormatWithApplicationNameV1 ( )

Definition at line 271 of file LogstashFormatterTest.php.

272 {
273 $formatter = new LogstashFormatter('app', 'test', null, 'ctxt_', LogstashFormatter::V1);
274 $record = array(
275 'level' => Logger::ERROR,
276 'level_name' => 'ERROR',
277 'channel' => 'meh',
278 'context' => array('from' => 'logger'),
279 'datetime' => new \DateTime("@0"),
280 'extra' => array('key' => 'pair'),
281 'message' => 'log'
282 );
283
284 $message = json_decode($formatter->format($record), true);
285
286 $this->assertArrayHasKey('type', $message);
287 $this->assertEquals('app', $message['type']);
288 }

References Monolog\Logger\ERROR, and Monolog\Formatter\LogstashFormatter\V1.

◆ testFormatWithContext()

Monolog\Formatter\LogstashFormatterTest::testFormatWithContext ( )

@covers Monolog\Formatter\LogstashFormatter::format

Definition at line 76 of file LogstashFormatterTest.php.

77 {
78 $formatter = new LogstashFormatter('test');
79 $record = array(
80 'level' => Logger::ERROR,
81 'level_name' => 'ERROR',
82 'channel' => 'meh',
83 'context' => array('from' => 'logger'),
84 'datetime' => new \DateTime("@0"),
85 'extra' => array('key' => 'pair'),
86 'message' => 'log'
87 );
88
89 $message = json_decode($formatter->format($record), true);
90
91 $message_array = $message['@fields'];
92
93 $this->assertArrayHasKey('ctxt_from', $message_array);
94 $this->assertEquals('logger', $message_array['ctxt_from']);
95
96 // Test with extraPrefix
97 $formatter = new LogstashFormatter('test', null, null, 'CTX');
98 $message = json_decode($formatter->format($record), true);
99
100 $message_array = $message['@fields'];
101
102 $this->assertArrayHasKey('CTXfrom', $message_array);
103 $this->assertEquals('logger', $message_array['CTXfrom']);
104 }

References Monolog\Logger\ERROR.

◆ testFormatWithContextV1()

Monolog\Formatter\LogstashFormatterTest::testFormatWithContextV1 ( )

@covers Monolog\Formatter\LogstashFormatter::format

Definition at line 216 of file LogstashFormatterTest.php.

217 {
218 $formatter = new LogstashFormatter('test', null, null, 'ctxt_', LogstashFormatter::V1);
219 $record = array(
220 'level' => Logger::ERROR,
221 'level_name' => 'ERROR',
222 'channel' => 'meh',
223 'context' => array('from' => 'logger'),
224 'datetime' => new \DateTime("@0"),
225 'extra' => array('key' => 'pair'),
226 'message' => 'log'
227 );
228
229 $message = json_decode($formatter->format($record), true);
230
231 $this->assertArrayHasKey('ctxt_from', $message);
232 $this->assertEquals('logger', $message['ctxt_from']);
233
234 // Test with extraPrefix
235 $formatter = new LogstashFormatter('test', null, null, 'CTX', LogstashFormatter::V1);
236 $message = json_decode($formatter->format($record), true);
237
238 $this->assertArrayHasKey('CTXfrom', $message);
239 $this->assertEquals('logger', $message['CTXfrom']);
240 }

References Monolog\Logger\ERROR, and Monolog\Formatter\LogstashFormatter\V1.

◆ testFormatWithExtra()

Monolog\Formatter\LogstashFormatterTest::testFormatWithExtra ( )

@covers Monolog\Formatter\LogstashFormatter::format

Definition at line 109 of file LogstashFormatterTest.php.

110 {
111 $formatter = new LogstashFormatter('test');
112 $record = array(
113 'level' => Logger::ERROR,
114 'level_name' => 'ERROR',
115 'channel' => 'meh',
116 'context' => array('from' => 'logger'),
117 'datetime' => new \DateTime("@0"),
118 'extra' => array('key' => 'pair'),
119 'message' => 'log'
120 );
121
122 $message = json_decode($formatter->format($record), true);
123
124 $message_array = $message['@fields'];
125
126 $this->assertArrayHasKey('key', $message_array);
127 $this->assertEquals('pair', $message_array['key']);
128
129 // Test with extraPrefix
130 $formatter = new LogstashFormatter('test', null, 'EXT');
131 $message = json_decode($formatter->format($record), true);
132
133 $message_array = $message['@fields'];
134
135 $this->assertArrayHasKey('EXTkey', $message_array);
136 $this->assertEquals('pair', $message_array['EXTkey']);
137 }

References Monolog\Logger\ERROR.

◆ testFormatWithExtraV1()

Monolog\Formatter\LogstashFormatterTest::testFormatWithExtraV1 ( )

@covers Monolog\Formatter\LogstashFormatter::format

Definition at line 245 of file LogstashFormatterTest.php.

246 {
247 $formatter = new LogstashFormatter('test', null, null, 'ctxt_', LogstashFormatter::V1);
248 $record = array(
249 'level' => Logger::ERROR,
250 'level_name' => 'ERROR',
251 'channel' => 'meh',
252 'context' => array('from' => 'logger'),
253 'datetime' => new \DateTime("@0"),
254 'extra' => array('key' => 'pair'),
255 'message' => 'log'
256 );
257
258 $message = json_decode($formatter->format($record), true);
259
260 $this->assertArrayHasKey('key', $message);
261 $this->assertEquals('pair', $message['key']);
262
263 // Test with extraPrefix
264 $formatter = new LogstashFormatter('test', null, 'EXT', 'ctxt_', LogstashFormatter::V1);
265 $message = json_decode($formatter->format($record), true);
266
267 $this->assertArrayHasKey('EXTkey', $message);
268 $this->assertEquals('pair', $message['EXTkey']);
269 }

References Monolog\Logger\ERROR, and Monolog\Formatter\LogstashFormatter\V1.

◆ testFormatWithFileAndLine()

Monolog\Formatter\LogstashFormatterTest::testFormatWithFileAndLine ( )

@covers Monolog\Formatter\LogstashFormatter::format

Definition at line 54 of file LogstashFormatterTest.php.

55 {
56 $formatter = new LogstashFormatter('test');
57 $record = array(
58 'level' => Logger::ERROR,
59 'level_name' => 'ERROR',
60 'channel' => 'meh',
61 'context' => array('from' => 'logger'),
62 'datetime' => new \DateTime("@0"),
63 'extra' => array('file' => 'test', 'line' => 14),
64 'message' => 'log',
65 );
66
67 $message = json_decode($formatter->format($record), true);
68
69 $this->assertEquals('test', $message['@fields']['file']);
70 $this->assertEquals(14, $message['@fields']['line']);
71 }

References Monolog\Logger\ERROR.

◆ testFormatWithFileAndLineV1()

Monolog\Formatter\LogstashFormatterTest::testFormatWithFileAndLineV1 ( )

@covers Monolog\Formatter\LogstashFormatter::format

Definition at line 194 of file LogstashFormatterTest.php.

195 {
196 $formatter = new LogstashFormatter('test', null, null, 'ctxt_', LogstashFormatter::V1);
197 $record = array(
198 'level' => Logger::ERROR,
199 'level_name' => 'ERROR',
200 'channel' => 'meh',
201 'context' => array('from' => 'logger'),
202 'datetime' => new \DateTime("@0"),
203 'extra' => array('file' => 'test', 'line' => 14),
204 'message' => 'log',
205 );
206
207 $message = json_decode($formatter->format($record), true);
208
209 $this->assertEquals('test', $message['file']);
210 $this->assertEquals(14, $message['line']);
211 }

References Monolog\Logger\ERROR, and Monolog\Formatter\LogstashFormatter\V1.


The documentation for this class was generated from the following file: