-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #267 from elecena/NanoLogger/fix-errors
NanoLogger: pushProcessor() now accepts LogRecord, not an array
- Loading branch information
Showing
2 changed files
with
48 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
use Monolog\Logger; | ||
use Monolog\LogRecord; | ||
use Nano\Logger\NanoLogger; | ||
|
||
/** | ||
* No-op logging handler. Keeps track of LogRecords sent to it. | ||
*/ | ||
class TestLoggingHandler extends Monolog\Handler\SyslogHandler | ||
{ | ||
public ?LogRecord $lastRecord = null; | ||
protected function write(LogRecord $record): void | ||
{ | ||
$this->lastRecord = $record; | ||
} | ||
} | ||
|
||
class NanoLoggerTest extends \Nano\NanoBaseTest | ||
{ | ||
public function testGetLogger(): void | ||
{ | ||
// register a global logging handler for easier testing | ||
$handler = new TestLoggingHandler(ident: 'foo'); | ||
NanoLogger::pushHandler($handler); | ||
|
||
$logger = NanoLogger::getLogger(name: __CLASS__, extraFields: ['foo'=>'bar']); | ||
$this->assertInstanceOf(Logger::class, $logger); | ||
$this->assertEquals(__CLASS__, $logger->getName()); | ||
|
||
// now, let's assert on what's getting logged | ||
$logger->info('Message'); | ||
$this->assertInstanceOf(LogRecord::class, $handler->lastRecord); | ||
|
||
$this->assertEquals(Monolog\Level::Info, $handler->lastRecord->level); | ||
$this->assertEquals('Message', $handler->lastRecord->message); | ||
$this->assertEquals('bar', $handler->lastRecord->extra['foo']); | ||
} | ||
} |