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

Public Member Functions

 setUp ()
 
 testDefaultFormatter ()
 Monologformat More...
 
 testFormatWithFileAndLine ()
 Monologformat More...
 
 testFormatInvalidFails ()
 Monologformat InvalidArgumentException More...
 
 testFormatWithContext ()
 Monologformat More...
 
 testFormatWithContextContainingException ()
 Monologformat More...
 
 testFormatWithExtra ()
 Monologformat More...
 
 testFormatWithLargeData ()
 

Private Member Functions

 isLegacy ()
 

Detailed Description

Definition at line 16 of file GelfMessageFormatterTest.php.

Member Function Documentation

◆ isLegacy()

Monolog\Formatter\GelfMessageFormatterTest::isLegacy ( )
private

Definition at line 230 of file GelfMessageFormatterTest.php.

Referenced by Monolog\Formatter\GelfMessageFormatterTest\testDefaultFormatter().

231  {
232  return interface_exists('\Gelf\IMessagePublisher');
233  }
+ Here is the caller graph for this function:

◆ setUp()

Monolog\Formatter\GelfMessageFormatterTest::setUp ( )

Definition at line 18 of file GelfMessageFormatterTest.php.

19  {
20  if (!class_exists('\Gelf\Message')) {
21  $this->markTestSkipped("graylog2/gelf-php or mlehner/gelf-php is not installed");
22  }
23  }

◆ testDefaultFormatter()

Monolog\Formatter\GelfMessageFormatterTest::testDefaultFormatter ( )

Monologformat

Definition at line 28 of file GelfMessageFormatterTest.php.

References array, Monolog\Logger\ERROR, and Monolog\Formatter\GelfMessageFormatterTest\isLegacy().

29  {
30  $formatter = new GelfMessageFormatter();
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 = $formatter->format($record);
42 
43  $this->assertInstanceOf('Gelf\Message', $message);
44  $this->assertEquals(0, $message->getTimestamp());
45  $this->assertEquals('log', $message->getShortMessage());
46  $this->assertEquals('meh', $message->getFacility());
47  $this->assertEquals(null, $message->getLine());
48  $this->assertEquals(null, $message->getFile());
49  $this->assertEquals($this->isLegacy() ? 3 : 'error', $message->getLevel());
50  $this->assertNotEmpty($message->getHost());
51 
52  $formatter = new GelfMessageFormatter('mysystem');
53 
54  $message = $formatter->format($record);
55 
56  $this->assertInstanceOf('Gelf\Message', $message);
57  $this->assertEquals('mysystem', $message->getHost());
58  }
const ERROR
Runtime errors.
Definition: Logger.php:57
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ testFormatInvalidFails()

Monolog\Formatter\GelfMessageFormatterTest::testFormatInvalidFails ( )

Monologformat InvalidArgumentException

Definition at line 87 of file GelfMessageFormatterTest.php.

References array, and Monolog\Logger\ERROR.

88  {
89  $formatter = new GelfMessageFormatter();
90  $record = array(
91  'level' => Logger::ERROR,
92  'level_name' => 'ERROR',
93  );
94 
95  $formatter->format($record);
96  }
const ERROR
Runtime errors.
Definition: Logger.php:57
Create styles array
The data for the language used.

◆ testFormatWithContext()

Monolog\Formatter\GelfMessageFormatterTest::testFormatWithContext ( )

Monologformat

Definition at line 101 of file GelfMessageFormatterTest.php.

References array, and Monolog\Logger\ERROR.

102  {
103  $formatter = new GelfMessageFormatter();
104  $record = array(
105  'level' => Logger::ERROR,
106  'level_name' => 'ERROR',
107  'channel' => 'meh',
108  'context' => array('from' => 'logger'),
109  'datetime' => new \DateTime("@0"),
110  'extra' => array('key' => 'pair'),
111  'message' => 'log',
112  );
113 
114  $message = $formatter->format($record);
115 
116  $this->assertInstanceOf('Gelf\Message', $message);
117 
118  $message_array = $message->toArray();
119 
120  $this->assertArrayHasKey('_ctxt_from', $message_array);
121  $this->assertEquals('logger', $message_array['_ctxt_from']);
122 
123  // Test with extraPrefix
124  $formatter = new GelfMessageFormatter(null, null, 'CTX');
125  $message = $formatter->format($record);
126 
127  $this->assertInstanceOf('Gelf\Message', $message);
128 
129  $message_array = $message->toArray();
130 
131  $this->assertArrayHasKey('_CTXfrom', $message_array);
132  $this->assertEquals('logger', $message_array['_CTXfrom']);
133  }
const ERROR
Runtime errors.
Definition: Logger.php:57
Create styles array
The data for the language used.

◆ testFormatWithContextContainingException()

Monolog\Formatter\GelfMessageFormatterTest::testFormatWithContextContainingException ( )

Monologformat

Definition at line 138 of file GelfMessageFormatterTest.php.

References array, and Monolog\Logger\ERROR.

139  {
140  $formatter = new GelfMessageFormatter();
141  $record = array(
142  'level' => Logger::ERROR,
143  'level_name' => 'ERROR',
144  'channel' => 'meh',
145  'context' => array('from' => 'logger', 'exception' => array(
146  'class' => '\Exception',
147  'file' => '/some/file/in/dir.php:56',
148  'trace' => array('/some/file/1.php:23', '/some/file/2.php:3'),
149  )),
150  'datetime' => new \DateTime("@0"),
151  'extra' => array(),
152  'message' => 'log',
153  );
154 
155  $message = $formatter->format($record);
156 
157  $this->assertInstanceOf('Gelf\Message', $message);
158 
159  $this->assertEquals("/some/file/in/dir.php", $message->getFile());
160  $this->assertEquals("56", $message->getLine());
161  }
const ERROR
Runtime errors.
Definition: Logger.php:57
Create styles array
The data for the language used.

◆ testFormatWithExtra()

Monolog\Formatter\GelfMessageFormatterTest::testFormatWithExtra ( )

Monologformat

Definition at line 166 of file GelfMessageFormatterTest.php.

References array, and Monolog\Logger\ERROR.

167  {
168  $formatter = new GelfMessageFormatter();
169  $record = array(
170  'level' => Logger::ERROR,
171  'level_name' => 'ERROR',
172  'channel' => 'meh',
173  'context' => array('from' => 'logger'),
174  'datetime' => new \DateTime("@0"),
175  'extra' => array('key' => 'pair'),
176  'message' => 'log',
177  );
178 
179  $message = $formatter->format($record);
180 
181  $this->assertInstanceOf('Gelf\Message', $message);
182 
183  $message_array = $message->toArray();
184 
185  $this->assertArrayHasKey('_key', $message_array);
186  $this->assertEquals('pair', $message_array['_key']);
187 
188  // Test with extraPrefix
189  $formatter = new GelfMessageFormatter(null, 'EXT');
190  $message = $formatter->format($record);
191 
192  $this->assertInstanceOf('Gelf\Message', $message);
193 
194  $message_array = $message->toArray();
195 
196  $this->assertArrayHasKey('_EXTkey', $message_array);
197  $this->assertEquals('pair', $message_array['_EXTkey']);
198  }
const ERROR
Runtime errors.
Definition: Logger.php:57
Create styles array
The data for the language used.

◆ testFormatWithFileAndLine()

Monolog\Formatter\GelfMessageFormatterTest::testFormatWithFileAndLine ( )

Monologformat

Definition at line 63 of file GelfMessageFormatterTest.php.

References array, and Monolog\Logger\ERROR.

64  {
65  $formatter = new GelfMessageFormatter();
66  $record = array(
67  'level' => Logger::ERROR,
68  'level_name' => 'ERROR',
69  'channel' => 'meh',
70  'context' => array('from' => 'logger'),
71  'datetime' => new \DateTime("@0"),
72  'extra' => array('file' => 'test', 'line' => 14),
73  'message' => 'log',
74  );
75 
76  $message = $formatter->format($record);
77 
78  $this->assertInstanceOf('Gelf\Message', $message);
79  $this->assertEquals('test', $message->getFile());
80  $this->assertEquals(14, $message->getLine());
81  }
const ERROR
Runtime errors.
Definition: Logger.php:57
Create styles array
The data for the language used.

◆ testFormatWithLargeData()

Monolog\Formatter\GelfMessageFormatterTest::testFormatWithLargeData ( )

Definition at line 200 of file GelfMessageFormatterTest.php.

References array, and Monolog\Logger\ERROR.

201  {
202  $formatter = new GelfMessageFormatter();
203  $record = array(
204  'level' => Logger::ERROR,
205  'level_name' => 'ERROR',
206  'channel' => 'meh',
207  'context' => array('exception' => str_repeat(' ', 32767)),
208  'datetime' => new \DateTime("@0"),
209  'extra' => array('key' => str_repeat(' ', 32767)),
210  'message' => 'log'
211  );
212  $message = $formatter->format($record);
213  $messageArray = $message->toArray();
214 
215  // 200 for padding + metadata
216  $length = 200;
217 
218  foreach ($messageArray as $key => $value) {
219  if (!in_array($key, array('level', 'timestamp'))) {
220  $length += strlen($value);
221  }
222  }
223 
224  // in graylog2/gelf-php before 1.4.1 empty strings are filtered and won't be included in the message
225  // though it should be sufficient to ensure that the entire message length does not exceed the maximum
226  // length being allowed
227  $this->assertLessThanOrEqual(32766, $length, 'The message length is no longer than the maximum allowed length');
228  }
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: