ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
Monolog\Formatter\LogstashFormatterTest Class Reference
+ Inheritance diagram for Monolog\Formatter\LogstashFormatterTest:
+ Collaboration diagram for Monolog\Formatter\LogstashFormatterTest:

Public Member Functions

 tearDown ()
 
 testDefaultFormatter ()
 Monologformat More...
 
 testFormatWithFileAndLine ()
 Monologformat More...
 
 testFormatWithContext ()
 Monologformat More...
 
 testFormatWithExtra ()
 Monologformat More...
 
 testFormatWithApplicationName ()
 
 testDefaultFormatterV1 ()
 Monologformat More...
 
 testFormatWithFileAndLineV1 ()
 Monologformat More...
 
 testFormatWithContextV1 ()
 Monologformat More...
 
 testFormatWithExtraV1 ()
 Monologformat 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.

19  {
20  \PHPUnit_Framework_Error_Warning::$enabled = true;
21 
22  return parent::tearDown();
23  }

◆ testDefaultFormatter()

Monolog\Formatter\LogstashFormatterTest::testDefaultFormatter ( )

Monologformat

Definition at line 28 of file LogstashFormatterTest.php.

References array, 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:57
Create styles array
The data for the language used.

◆ testDefaultFormatterV1()

Monolog\Formatter\LogstashFormatterTest::testDefaultFormatterV1 ( )

Monologformat

Definition at line 168 of file LogstashFormatterTest.php.

References array, 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:57
Create styles array
The data for the language used.

◆ testFormatWithApplicationName()

Monolog\Formatter\LogstashFormatterTest::testFormatWithApplicationName ( )

Definition at line 146 of file LogstashFormatterTest.php.

References array, 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:57
Create styles array
The data for the language used.

◆ testFormatWithApplicationNameV1()

Monolog\Formatter\LogstashFormatterTest::testFormatWithApplicationNameV1 ( )

Definition at line 278 of file LogstashFormatterTest.php.

References array, 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:57
Create styles array
The data for the language used.

◆ testFormatWithContext()

Monolog\Formatter\LogstashFormatterTest::testFormatWithContext ( )

Monologformat

Definition at line 83 of file LogstashFormatterTest.php.

References array, 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:57
Create styles array
The data for the language used.

◆ testFormatWithContextV1()

Monolog\Formatter\LogstashFormatterTest::testFormatWithContextV1 ( )

Monologformat

Definition at line 223 of file LogstashFormatterTest.php.

References array, 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:57
Create styles array
The data for the language used.

◆ testFormatWithExtra()

Monolog\Formatter\LogstashFormatterTest::testFormatWithExtra ( )

Monologformat

Definition at line 116 of file LogstashFormatterTest.php.

References array, 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:57
Create styles array
The data for the language used.

◆ testFormatWithExtraV1()

Monolog\Formatter\LogstashFormatterTest::testFormatWithExtraV1 ( )

Monologformat

Definition at line 252 of file LogstashFormatterTest.php.

References array, 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:57
Create styles array
The data for the language used.

◆ testFormatWithFileAndLine()

Monolog\Formatter\LogstashFormatterTest::testFormatWithFileAndLine ( )

Monologformat

Definition at line 61 of file LogstashFormatterTest.php.

References array, 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:57
Create styles array
The data for the language used.

◆ testFormatWithFileAndLineV1()

Monolog\Formatter\LogstashFormatterTest::testFormatWithFileAndLineV1 ( )

Monologformat

Definition at line 201 of file LogstashFormatterTest.php.

References array, 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:57
Create styles array
The data for the language used.

◆ testFormatWithLatin9Data()

Monolog\Formatter\LogstashFormatterTest::testFormatWithLatin9Data ( )

Definition at line 297 of file LogstashFormatterTest.php.

References array, 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:57
Create styles array
The data for the language used.

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