mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-09 14:46:46 +02:00
Merge remote-tracking branch 'webfactory/master'
This commit is contained in:
@@ -184,6 +184,7 @@ Processors
|
||||
- _MemoryUsageProcessor_: Adds the current memory usage to a log record.
|
||||
- _MemoryPeakUsageProcessor_: Adds the peak memory usage to a log record.
|
||||
- _ProcessIdProcessor_: Adds the process id to a log record.
|
||||
- _UidProcessor_: Adds a unique identifier to a log record.
|
||||
|
||||
About
|
||||
=====
|
||||
|
36
src/Monolog/Processor/UidProcessor.php
Normal file
36
src/Monolog/Processor/UidProcessor.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Monolog package.
|
||||
*
|
||||
* (c) Jordi Boggiano <j.boggiano@seld.be>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Monolog\Processor;
|
||||
|
||||
/**
|
||||
* Adds a unique identifier into records
|
||||
*
|
||||
* @author Simon Mönch <sm@webfactory.de>
|
||||
*/
|
||||
class UidProcessor
|
||||
{
|
||||
private $uid;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
if (null === $this->uid) {
|
||||
$this->uid = substr(hash('md5', uniqid('', true)), 0, 7);
|
||||
}
|
||||
}
|
||||
|
||||
public function __invoke(array $record)
|
||||
{
|
||||
$record['extra']['uid'] = $this->uid;
|
||||
|
||||
return $record;
|
||||
}
|
||||
}
|
27
tests/Monolog/Processor/UidProcessorTest.php
Normal file
27
tests/Monolog/Processor/UidProcessorTest.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Monolog package.
|
||||
*
|
||||
* (c) Jordi Boggiano <j.boggiano@seld.be>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Monolog\Processor;
|
||||
|
||||
use Monolog\TestCase;
|
||||
|
||||
class UidProcessorTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers Monolog\Processor\UidProcessor::__invoke
|
||||
*/
|
||||
public function testProcessor()
|
||||
{
|
||||
$processor = new UidProcessor();
|
||||
$record = $processor($this->getRecord());
|
||||
$this->assertArrayHasKey('uid', $record['extra']);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user