1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-25 06:00:57 +02:00

Code cleanups

This commit is contained in:
Jordi Boggiano
2022-03-05 14:03:57 +01:00
parent b586dbe8e6
commit 5eb9b8ed93
109 changed files with 418 additions and 549 deletions

View File

@@ -145,7 +145,7 @@ class BufferHandlerTest extends TestCase
$test = new TestHandler();
$handler = new BufferHandler($test);
$handler->pushProcessor(function ($record) {
$record['extra']['foo'] = true;
$record->extra['foo'] = true;
return $record;
});

View File

@@ -122,7 +122,7 @@ class DeduplicationHandlerTest extends TestCase
// log is written as none of them are duplicate
$handler->flush();
$this->assertSame(
$record['datetime']->getTimestamp() . ":ERROR:test\n" .
$record->datetime->getTimestamp() . ":ERROR:test\n" .
$record2['datetime']->getTimestamp() . ":CRITICAL:test\n" .
$record3['datetime']->getTimestamp() . ":CRITICAL:test\n",
file_get_contents(sys_get_temp_dir() . '/monolog_dedup.log')
@@ -144,7 +144,7 @@ class DeduplicationHandlerTest extends TestCase
// log should now contain the new errors and the previous one that was recent enough
$this->assertSame(
$record3['datetime']->getTimestamp() . ":CRITICAL:test\n" .
$record['datetime']->getTimestamp() . ":ERROR:test\n" .
$record->datetime->getTimestamp() . ":ERROR:test\n" .
$record2['datetime']->getTimestamp() . ":CRITICAL:test\n",
file_get_contents(sys_get_temp_dir() . '/monolog_dedup.log')
);

View File

@@ -38,7 +38,7 @@ class DoctrineCouchDBHandlerTest extends TestCase
'level' => Logger::WARNING,
'level_name' => 'WARNING',
'channel' => 'test',
'datetime' => (string) $record['datetime'],
'datetime' => (string) $record->datetime,
'extra' => [],
];

View File

@@ -98,7 +98,7 @@ class FallbackGroupHandlerTest extends TestCase
$test = new TestHandler();
$handler = new FallbackGroupHandler([$test]);
$handler->pushProcessor(function ($record) {
$record['extra']['foo'] = true;
$record->extra['foo'] = true;
return $record;
});
@@ -118,12 +118,12 @@ class FallbackGroupHandlerTest extends TestCase
$testHandlers = [$testHandlerOne, $testHandlerTwo];
$handler = new FallbackGroupHandler($testHandlers);
$handler->pushProcessor(function ($record) {
$record['extra']['foo'] = true;
$record->extra['foo'] = true;
return $record;
});
$handler->pushProcessor(function ($record) {
$record['extra']['foo2'] = true;
$record->extra['foo2'] = true;
return $record;
});

View File

@@ -110,7 +110,7 @@ class FilterHandlerTest extends TestCase
$handler = new FilterHandler($test, Logger::DEBUG, Logger::EMERGENCY);
$handler->pushProcessor(
function ($record) {
$record['extra']['foo'] = true;
$record->extra['foo'] = true;
return $record;
}

View File

@@ -56,8 +56,8 @@ class GelfHandlerTest extends TestCase
$expectedMessage
->setLevel(7)
->setFacility("test")
->setShortMessage($record['message'])
->setTimestamp($record['datetime'])
->setShortMessage($record->message)
->setTimestamp($record->datetime)
;
$messagePublisher = $this->getMessagePublisher();
@@ -77,8 +77,8 @@ class GelfHandlerTest extends TestCase
$expectedMessage
->setLevel(4)
->setFacility("test")
->setShortMessage($record['message'])
->setTimestamp($record['datetime'])
->setShortMessage($record->message)
->setTimestamp($record->datetime)
;
$messagePublisher = $this->getMessagePublisher();
@@ -105,8 +105,8 @@ class GelfHandlerTest extends TestCase
->setLevel(4)
->setFacility("test")
->setHost("mysystem")
->setShortMessage($record['message'])
->setTimestamp($record['datetime'])
->setShortMessage($record->message)
->setTimestamp($record->datetime)
->setAdditional("EXTblarg", 'yep')
->setAdditional("CTXfrom", 'logger')
;

View File

@@ -78,7 +78,7 @@ class GroupHandlerTest extends TestCase
$test = new TestHandler();
$handler = new GroupHandler([$test]);
$handler->pushProcessor(function ($record) {
$record['extra']['foo'] = true;
$record->extra['foo'] = true;
return $record;
});
@@ -96,12 +96,12 @@ class GroupHandlerTest extends TestCase
$testHandlers = [new TestHandler(), new TestHandler()];
$handler = new GroupHandler($testHandlers);
$handler->pushProcessor(function ($record) {
$record['extra']['foo'] = true;
$record->extra['foo'] = true;
return $record;
});
$handler->pushProcessor(function ($record) {
$record['extra']['foo2'] = true;
$record->extra['foo2'] = true;
return $record;
});

View File

@@ -65,7 +65,7 @@ class MailHandlerTest extends TestCase
$record = $this->getRecord();
$records = [$record];
$records[0]['formatted'] = '['.$record['datetime'].'] test.WARNING: test [] []'."\n";
$records[0]['formatted'] = '['.$record->datetime.'] test.WARNING: test [] []'."\n";
$handler->expects($this->once())
->method('send')

View File

@@ -44,7 +44,7 @@ class MongoDBHandlerTest extends TestCase
$record = $this->getRecord();
$expected = $record->toArray();
$expected['datetime'] = new \MongoDB\BSON\UTCDateTime((int) floor(((float) $record['datetime']->format('U.u')) * 1000));
$expected['datetime'] = new \MongoDB\BSON\UTCDateTime((int) floor(((float) $record->datetime->format('U.u')) * 1000));
$collection->expects($this->once())
->method('insertOne')

View File

@@ -67,7 +67,7 @@ class NewRelicHandlerTest extends TestCase
public function testThehandlerCanAddExtraParamsToTheNewRelicTrace()
{
$record = $this->getRecord(Logger::ERROR, 'log message');
$record['extra'] = ['c' => 'd'];
$record->extra = ['c' => 'd'];
$handler = new StubNewRelicHandler();
$handler->handle($record);
@@ -78,7 +78,7 @@ class NewRelicHandlerTest extends TestCase
public function testThehandlerCanAddExplodedExtraParamsToTheNewRelicTrace()
{
$record = $this->getRecord(Logger::ERROR, 'log message');
$record['extra'] = ['c' => ['key1' => 'value1', 'key2' => 'value2']];
$record->extra = ['c' => ['key1' => 'value1', 'key2' => 'value2']];
$handler = new StubNewRelicHandler(Logger::ERROR, true, self::$appname, true);
$handler->handle($record);
@@ -92,7 +92,7 @@ class NewRelicHandlerTest extends TestCase
public function testThehandlerCanAddExtraContextAndParamsToTheNewRelicTrace()
{
$record = $this->getRecord(Logger::ERROR, 'log message', ['a' => 'b']);
$record['extra'] = ['c' => 'd'];
$record->extra = ['c' => 'd'];
$handler = new StubNewRelicHandler();
$handler->handle($record);

View File

@@ -168,7 +168,7 @@ class SlackRecordTest extends TestCase
->expects($this->any())
->method('format')
->will($this->returnCallback(function ($record) {
return $record['message'] . 'test';
return $record->message . 'test';
}));
$formatter2 = $this->createMock('Monolog\\Formatter\\FormatterInterface');
@@ -176,7 +176,7 @@ class SlackRecordTest extends TestCase
->expects($this->any())
->method('format')
->will($this->returnCallback(function ($record) {
return $record['message'] . 'test1';
return $record->message . 'test1';
}));
$message = 'Test message';
@@ -345,7 +345,7 @@ class SlackRecordTest extends TestCase
$attachment = $data['attachments'][0];
$this->assertArrayHasKey('ts', $attachment);
$this->assertSame($record['datetime']->getTimestamp(), $attachment['ts']);
$this->assertSame($record->datetime->getTimestamp(), $attachment['ts']);
}
public function testContextHasException()
@@ -361,9 +361,9 @@ class SlackRecordTest extends TestCase
$record = $this->getRecord(
Logger::WARNING,
'test',
array('info' => array('library' => 'monolog', 'author' => 'Jordi'))
context: array('info' => array('library' => 'monolog', 'author' => 'Jordi')),
extra: array('tags' => array('web', 'cli')),
);
$record['extra'] = array('tags' => array('web', 'cli'));
$slackRecord = new SlackRecord(null, null, true, null, false, true, array('context.info.library', 'extra.tags.1'));
$data = $slackRecord->getSlackData($record);

View File

@@ -50,7 +50,7 @@ class SlackWebhookHandlerTest extends TestCase
),
'title' => 'Message',
'mrkdwn_in' => array('fields'),
'ts' => $record['datetime']->getTimestamp(),
'ts' => $record->datetime->getTimestamp(),
'footer' => null,
'footer_icon' => null,
),

View File

@@ -78,7 +78,7 @@ class WhatFailureGroupHandlerTest extends TestCase
$test = new TestHandler();
$handler = new WhatFailureGroupHandler([$test]);
$handler->pushProcessor(function ($record) {
$record['extra']['foo'] = true;
$record->extra['foo'] = true;
return $record;
});
@@ -96,12 +96,12 @@ class WhatFailureGroupHandlerTest extends TestCase
$testHandlers = array(new TestHandler(), new TestHandler());
$handler = new WhatFailureGroupHandler($testHandlers);
$handler->pushProcessor(function ($record) {
$record['extra']['foo'] = true;
$record->extra['foo'] = true;
return $record;
});
$handler->pushProcessor(function ($record) {
$record['extra']['foo2'] = true;
$record->extra['foo2'] = true;
return $record;
});
@@ -127,7 +127,7 @@ class WhatFailureGroupHandlerTest extends TestCase
$exception = new ExceptionTestHandler();
$handler = new WhatFailureGroupHandler([$exception, $test, $exception]);
$handler->pushProcessor(function ($record) {
$record['extra']['foo'] = true;
$record->extra['foo'] = true;
return $record;
});

View File

@@ -32,7 +32,7 @@ class ZendMonitorHandlerTest extends TestCase
{
$record = $this->getRecord();
$formatterResult = [
'message' => $record['message'],
'message' => $record->message,
];
$zendMonitor = $this->getMockBuilder('Monolog\Handler\ZendMonitorHandler')
@@ -56,10 +56,10 @@ class ZendMonitorHandlerTest extends TestCase
$zendMonitor->expects($this->once())
->method('writeZendMonitorCustomEvent')
->with(
Logger::getLevelName($record['level']),
$record['message'],
Logger::getLevelName($record->level),
$record->message,
$formatterResult,
$levelMap[$record['level']]
$levelMap[$record->level]
);
$zendMonitor->handle($record);