ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Monolog\Formatter\LogstashFormatterTest Class Reference
+ Inheritance diagram for Monolog\Formatter\LogstashFormatterTest:
+ Collaboration diagram for Monolog\Formatter\LogstashFormatterTest:

Public Member Functions

 tearDown ()
 
 testDefaultFormatter ()
 Monolog::format More...
 
 testFormatWithFileAndLine ()
 Monolog::format More...
 
 testFormatWithContext ()
 Monolog::format More...
 
 testFormatWithExtra ()
 Monolog::format More...
 
 testFormatWithApplicationName ()
 
 testDefaultFormatterV1 ()
 Monolog::format More...
 
 testFormatWithFileAndLineV1 ()
 Monolog::format More...
 
 testFormatWithContextV1 ()
 Monolog::format More...
 
 testFormatWithExtraV1 ()
 Monolog::format More...
 
 testFormatWithApplicationNameV1 ()
 
 testFormatWithLatin9Data ()
 

Detailed Description

Definition at line 16 of file LogstashFormatterTest.php.

Member Function Documentation

◆ tearDown()

Monolog\Formatter\LogstashFormatterTest::tearDown ( )

Definition at line 18 of file LogstashFormatterTest.php.

References Sabre\DAV\tearDown().

19  {
20  \PHPUnit_Framework_Error_Warning::$enabled = true;
21 
22  return parent::tearDown();
23  }
+ Here is the call graph for this function:

◆ testDefaultFormatter()

Monolog\Formatter\LogstashFormatterTest::testDefaultFormatter ( )

Monolog::format

Definition at line 28 of file LogstashFormatterTest.php.

References $message, and Monolog\Logger\ERROR.

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

◆ testDefaultFormatterV1()

Monolog\Formatter\LogstashFormatterTest::testDefaultFormatterV1 ( )

Monolog::format

Definition at line 168 of file LogstashFormatterTest.php.

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

169  {
170  $formatter = new LogstashFormatter('test', 'hostname', null, 'ctxt_', LogstashFormatter::V1);
171  $record = array(
172  'level' => Logger::ERROR,
173  'level_name' => 'ERROR',
174  'channel' => 'meh',
175  'context' => array(),
176  'datetime' => new \DateTime("@0"),
177  'extra' => array(),
178  'message' => 'log',
179  );
180 
181  $message = json_decode($formatter->format($record), true);
182 
183  $this->assertEquals("1970-01-01T00:00:00.000000+00:00", $message['@timestamp']);
184  $this->assertEquals("1", $message['@version']);
185  $this->assertEquals('log', $message['message']);
186  $this->assertEquals('meh', $message['channel']);
187  $this->assertEquals('ERROR', $message['level']);
188  $this->assertEquals('test', $message['type']);
189  $this->assertEquals('hostname', $message['host']);
190 
191  $formatter = new LogstashFormatter('mysystem', null, null, 'ctxt_', LogstashFormatter::V1);
192 
193  $message = json_decode($formatter->format($record), true);
194 
195  $this->assertEquals('mysystem', $message['type']);
196  }
const ERROR
Runtime errors.
Definition: Logger.php:58
catch(Exception $e) $message

◆ testFormatWithApplicationName()

Monolog\Formatter\LogstashFormatterTest::testFormatWithApplicationName ( )

Definition at line 146 of file LogstashFormatterTest.php.

References $message, and Monolog\Logger\ERROR.

147  {
148  $formatter = new LogstashFormatter('app', 'test');
149  $record = array(
150  'level' => Logger::ERROR,
151  'level_name' => 'ERROR',
152  'channel' => 'meh',
153  'context' => array('from' => 'logger'),
154  'datetime' => new \DateTime("@0"),
155  'extra' => array('key' => 'pair'),
156  'message' => 'log',
157  );
158 
159  $message = json_decode($formatter->format($record), true);
160 
161  $this->assertArrayHasKey('@type', $message);
162  $this->assertEquals('app', $message['@type']);
163  }
const ERROR
Runtime errors.
Definition: Logger.php:58
catch(Exception $e) $message

◆ testFormatWithApplicationNameV1()

Monolog\Formatter\LogstashFormatterTest::testFormatWithApplicationNameV1 ( )

Definition at line 278 of file LogstashFormatterTest.php.

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

279  {
280  $formatter = new LogstashFormatter('app', 'test', null, 'ctxt_', LogstashFormatter::V1);
281  $record = array(
282  'level' => Logger::ERROR,
283  'level_name' => 'ERROR',
284  'channel' => 'meh',
285  'context' => array('from' => 'logger'),
286  'datetime' => new \DateTime("@0"),
287  'extra' => array('key' => 'pair'),
288  'message' => 'log',
289  );
290 
291  $message = json_decode($formatter->format($record), true);
292 
293  $this->assertArrayHasKey('type', $message);
294  $this->assertEquals('app', $message['type']);
295  }
const ERROR
Runtime errors.
Definition: Logger.php:58
catch(Exception $e) $message

◆ testFormatWithContext()

Monolog\Formatter\LogstashFormatterTest::testFormatWithContext ( )

Monolog::format

Definition at line 83 of file LogstashFormatterTest.php.

References $message, and Monolog\Logger\ERROR.

84  {
85  $formatter = new LogstashFormatter('test');
86  $record = array(
87  'level' => Logger::ERROR,
88  'level_name' => 'ERROR',
89  'channel' => 'meh',
90  'context' => array('from' => 'logger'),
91  'datetime' => new \DateTime("@0"),
92  'extra' => array('key' => 'pair'),
93  'message' => 'log',
94  );
95 
96  $message = json_decode($formatter->format($record), true);
97 
98  $message_array = $message['@fields'];
99 
100  $this->assertArrayHasKey('ctxt_from', $message_array);
101  $this->assertEquals('logger', $message_array['ctxt_from']);
102 
103  // Test with extraPrefix
104  $formatter = new LogstashFormatter('test', null, null, 'CTX');
105  $message = json_decode($formatter->format($record), true);
106 
107  $message_array = $message['@fields'];
108 
109  $this->assertArrayHasKey('CTXfrom', $message_array);
110  $this->assertEquals('logger', $message_array['CTXfrom']);
111  }
const ERROR
Runtime errors.
Definition: Logger.php:58
catch(Exception $e) $message

◆ testFormatWithContextV1()

Monolog\Formatter\LogstashFormatterTest::testFormatWithContextV1 ( )

Monolog::format

Definition at line 223 of file LogstashFormatterTest.php.

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

224  {
225  $formatter = new LogstashFormatter('test', null, null, 'ctxt_', LogstashFormatter::V1);
226  $record = array(
227  'level' => Logger::ERROR,
228  'level_name' => 'ERROR',
229  'channel' => 'meh',
230  'context' => array('from' => 'logger'),
231  'datetime' => new \DateTime("@0"),
232  'extra' => array('key' => 'pair'),
233  'message' => 'log',
234  );
235 
236  $message = json_decode($formatter->format($record), true);
237 
238  $this->assertArrayHasKey('ctxt_from', $message);
239  $this->assertEquals('logger', $message['ctxt_from']);
240 
241  // Test with extraPrefix
242  $formatter = new LogstashFormatter('test', null, null, 'CTX', LogstashFormatter::V1);
243  $message = json_decode($formatter->format($record), true);
244 
245  $this->assertArrayHasKey('CTXfrom', $message);
246  $this->assertEquals('logger', $message['CTXfrom']);
247  }
const ERROR
Runtime errors.
Definition: Logger.php:58
catch(Exception $e) $message

◆ testFormatWithExtra()

Monolog\Formatter\LogstashFormatterTest::testFormatWithExtra ( )

Monolog::format

Definition at line 116 of file LogstashFormatterTest.php.

References $message, and Monolog\Logger\ERROR.

117  {
118  $formatter = new LogstashFormatter('test');
119  $record = array(
120  'level' => Logger::ERROR,
121  'level_name' => 'ERROR',
122  'channel' => 'meh',
123  'context' => array('from' => 'logger'),
124  'datetime' => new \DateTime("@0"),
125  'extra' => array('key' => 'pair'),
126  'message' => 'log',
127  );
128 
129  $message = json_decode($formatter->format($record), true);
130 
131  $message_array = $message['@fields'];
132 
133  $this->assertArrayHasKey('key', $message_array);
134  $this->assertEquals('pair', $message_array['key']);
135 
136  // Test with extraPrefix
137  $formatter = new LogstashFormatter('test', null, 'EXT');
138  $message = json_decode($formatter->format($record), true);
139 
140  $message_array = $message['@fields'];
141 
142  $this->assertArrayHasKey('EXTkey', $message_array);
143  $this->assertEquals('pair', $message_array['EXTkey']);
144  }
const ERROR
Runtime errors.
Definition: Logger.php:58
catch(Exception $e) $message

◆ testFormatWithExtraV1()

Monolog\Formatter\LogstashFormatterTest::testFormatWithExtraV1 ( )

Monolog::format

Definition at line 252 of file LogstashFormatterTest.php.

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

253  {
254  $formatter = new LogstashFormatter('test', null, null, 'ctxt_', LogstashFormatter::V1);
255  $record = array(
256  'level' => Logger::ERROR,
257  'level_name' => 'ERROR',
258  'channel' => 'meh',
259  'context' => array('from' => 'logger'),
260  'datetime' => new \DateTime("@0"),
261  'extra' => array('key' => 'pair'),
262  'message' => 'log',
263  );
264 
265  $message = json_decode($formatter->format($record), true);
266 
267  $this->assertArrayHasKey('key', $message);
268  $this->assertEquals('pair', $message['key']);
269 
270  // Test with extraPrefix
271  $formatter = new LogstashFormatter('test', null, 'EXT', 'ctxt_', LogstashFormatter::V1);
272  $message = json_decode($formatter->format($record), true);
273 
274  $this->assertArrayHasKey('EXTkey', $message);
275  $this->assertEquals('pair', $message['EXTkey']);
276  }
const ERROR
Runtime errors.
Definition: Logger.php:58
catch(Exception $e) $message

◆ testFormatWithFileAndLine()

Monolog\Formatter\LogstashFormatterTest::testFormatWithFileAndLine ( )

Monolog::format

Definition at line 61 of file LogstashFormatterTest.php.

References $message, and Monolog\Logger\ERROR.

62  {
63  $formatter = new LogstashFormatter('test');
64  $record = array(
65  'level' => Logger::ERROR,
66  'level_name' => 'ERROR',
67  'channel' => 'meh',
68  'context' => array('from' => 'logger'),
69  'datetime' => new \DateTime("@0"),
70  'extra' => array('file' => 'test', 'line' => 14),
71  'message' => 'log',
72  );
73 
74  $message = json_decode($formatter->format($record), true);
75 
76  $this->assertEquals('test', $message['@fields']['file']);
77  $this->assertEquals(14, $message['@fields']['line']);
78  }
const ERROR
Runtime errors.
Definition: Logger.php:58
catch(Exception $e) $message

◆ testFormatWithFileAndLineV1()

Monolog\Formatter\LogstashFormatterTest::testFormatWithFileAndLineV1 ( )

Monolog::format

Definition at line 201 of file LogstashFormatterTest.php.

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

202  {
203  $formatter = new LogstashFormatter('test', null, null, 'ctxt_', LogstashFormatter::V1);
204  $record = array(
205  'level' => Logger::ERROR,
206  'level_name' => 'ERROR',
207  'channel' => 'meh',
208  'context' => array('from' => 'logger'),
209  'datetime' => new \DateTime("@0"),
210  'extra' => array('file' => 'test', 'line' => 14),
211  'message' => 'log',
212  );
213 
214  $message = json_decode($formatter->format($record), true);
215 
216  $this->assertEquals('test', $message['file']);
217  $this->assertEquals(14, $message['line']);
218  }
const ERROR
Runtime errors.
Definition: Logger.php:58
catch(Exception $e) $message

◆ testFormatWithLatin9Data()

Monolog\Formatter\LogstashFormatterTest::testFormatWithLatin9Data ( )

Definition at line 297 of file LogstashFormatterTest.php.

References $message, and Monolog\Logger\ERROR.

298  {
299  if (version_compare(PHP_VERSION, '5.5.0', '<')) {
300  // Ignore the warning that will be emitted by PHP <5.5.0
301  \PHPUnit_Framework_Error_Warning::$enabled = false;
302  }
303  $formatter = new LogstashFormatter('test', 'hostname');
304  $record = array(
305  'level' => Logger::ERROR,
306  'level_name' => 'ERROR',
307  'channel' => '¯\_(ツ)_/¯',
308  'context' => array(),
309  'datetime' => new \DateTime("@0"),
310  'extra' => array(
311  'user_agent' => "\xD6WN; FBCR/OrangeEspa\xF1a; Vers\xE3o/4.0; F\xE4rist",
312  ),
313  'message' => 'log',
314  );
315 
316  $message = json_decode($formatter->format($record), true);
317 
318  $this->assertEquals("1970-01-01T00:00:00.000000+00:00", $message['@timestamp']);
319  $this->assertEquals('log', $message['@message']);
320  $this->assertEquals('¯\_(ツ)_/¯', $message['@fields']['channel']);
321  $this->assertContains('¯\_(ツ)_/¯', $message['@tags']);
322  $this->assertEquals(Logger::ERROR, $message['@fields']['level']);
323  $this->assertEquals('test', $message['@type']);
324  $this->assertEquals('hostname', $message['@source']);
325  if (version_compare(PHP_VERSION, '5.5.0', '>=')) {
326  $this->assertEquals('ÖWN; FBCR/OrangeEspaña; Versão/4.0; Färist', $message['@fields']['user_agent']);
327  } else {
328  // PHP <5.5 does not return false for an element encoding failure,
329  // instead it emits a warning (possibly) and nulls the value.
330  $this->assertEquals(null, $message['@fields']['user_agent']);
331  }
332  }
const ERROR
Runtime errors.
Definition: Logger.php:58
catch(Exception $e) $message

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