-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add HighResolutionTimestampProcessor
- Loading branch information
1 parent
083f2c5
commit 26411ee
Showing
10 changed files
with
83 additions
and
2 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
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,25 @@ | ||
<?php | ||
|
||
/* | ||
* (c) Alexandre Daubois <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace MonologProcessorCollection; | ||
|
||
use Monolog\LogRecord; | ||
|
||
/** | ||
* Add the high resolution timestamp to the log record. | ||
*/ | ||
final class HighResolutionTimestampProcessor extends AbstractThresholdProcessor | ||
{ | ||
protected function process(LogRecord $record): LogRecord | ||
{ | ||
$record['extra']['hrtime'] = \hrtime(true); | ||
|
||
return $record; | ||
} | ||
} |
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
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
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,34 @@ | ||
<?php | ||
|
||
/* | ||
* (c) Alexandre Daubois <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace MonologProcessorCollection\Tests; | ||
|
||
use Monolog\Handler\TestHandler; | ||
use Monolog\Level; | ||
use MonologProcessorCollection\HighResolutionTimestampProcessor; | ||
use PHPUnit\Framework\Attributes\CoversClass; | ||
|
||
#[CoversClass(HighResolutionTimestampProcessor::class)] | ||
class HighResolutionTimestampProcessorTest extends AbstractProcessorTestCase | ||
{ | ||
public function testItWorks(): void | ||
{ | ||
$processor = new HighResolutionTimestampProcessor(); | ||
|
||
$handler = new TestHandler(); | ||
$handler->pushProcessor($processor); | ||
$handler->handle($this->createRecord(Level::Notice)); | ||
|
||
$this->assertTrue($handler->hasNoticeRecords()); | ||
$record = $handler->getRecords()[0]; | ||
|
||
$this->assertArrayHasKey('hrtime', $record->extra); | ||
$this->assertIsNotArray($record->extra['hrtime']); | ||
} | ||
} |