-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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 #997 from lyrixx/resetable
Added a new ResettableInterface and implemented it where possible.
- Loading branch information
Showing
16 changed files
with
200 additions
and
15 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 |
---|---|---|
|
@@ -11,16 +11,17 @@ | |
|
||
namespace Monolog\Handler; | ||
|
||
use Monolog\Logger; | ||
use Monolog\Formatter\FormatterInterface; | ||
use Monolog\Formatter\LineFormatter; | ||
use Monolog\Logger; | ||
use Monolog\ResettableInterface; | ||
|
||
/** | ||
* Base Handler class providing the Handler structure | ||
* | ||
* @author Jordi Boggiano <[email protected]> | ||
*/ | ||
abstract class AbstractHandler implements HandlerInterface | ||
abstract class AbstractHandler implements HandlerInterface, ResettableInterface | ||
{ | ||
protected $level = Logger::DEBUG; | ||
protected $bubble = true; | ||
|
@@ -174,6 +175,17 @@ public function __destruct() | |
} | ||
} | ||
|
||
public function reset() | ||
{ | ||
$this->close(); | ||
|
||
foreach ($this->processors as $processor) { | ||
if ($processor instanceof ResettableInterface) { | ||
$processor->reset(); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Gets the default formatter. | ||
* | ||
|
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 |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
|
||
namespace Monolog\Handler; | ||
|
||
use Monolog\ResettableInterface; | ||
use Monolog\Formatter\FormatterInterface; | ||
|
||
/** | ||
|
@@ -30,7 +31,7 @@ | |
* | ||
* @author Alexey Karapetov <[email protected]> | ||
*/ | ||
class HandlerWrapper implements HandlerInterface | ||
class HandlerWrapper implements HandlerInterface, ResettableInterface | ||
{ | ||
/** | ||
* @var HandlerInterface | ||
|
@@ -105,4 +106,11 @@ public function getFormatter() | |
{ | ||
return $this->handler->getFormatter(); | ||
} | ||
|
||
public function reset() | ||
{ | ||
if ($this->handler instanceof ResettableInterface) { | ||
return $this->handler->reset(); | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -25,7 +25,7 @@ | |
* | ||
* @author Jordi Boggiano <[email protected]> | ||
*/ | ||
class Logger implements LoggerInterface | ||
class Logger implements LoggerInterface, ResettableInterface | ||
{ | ||
/** | ||
* Detailed debug information | ||
|
@@ -354,6 +354,21 @@ public function addRecord($level, $message, array $context = array()) | |
return true; | ||
} | ||
|
||
public function reset() | ||
{ | ||
foreach ($this->handlers as $handler) { | ||
if ($handler instanceof ResettableInterface) { | ||
$handler->reset(); | ||
} | ||
} | ||
|
||
foreach ($this->processors as $processor) { | ||
if ($processor instanceof ResettableInterface) { | ||
$processor->reset(); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Adds a log record at the DEBUG level. | ||
* | ||
|
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 |
---|---|---|
|
@@ -11,12 +11,14 @@ | |
|
||
namespace Monolog\Processor; | ||
|
||
use Monolog\ResettableInterface; | ||
|
||
/** | ||
* Adds a unique identifier into records | ||
* | ||
* @author Simon Mönch <[email protected]> | ||
*/ | ||
class UidProcessor implements ProcessorInterface | ||
class UidProcessor implements ProcessorInterface, ResettableInterface | ||
{ | ||
private $uid; | ||
|
||
|
@@ -26,7 +28,8 @@ public function __construct($length = 7) | |
throw new \InvalidArgumentException('The uid length must be an integer between 1 and 32'); | ||
} | ||
|
||
$this->uid = substr(hash('md5', uniqid('', true)), 0, $length); | ||
|
||
$this->uid = $this->generateUid($length); | ||
} | ||
|
||
public function __invoke(array $record) | ||
|
@@ -43,4 +46,14 @@ public function getUid() | |
{ | ||
return $this->uid; | ||
} | ||
|
||
public function reset() | ||
{ | ||
$this->uid = $this->generateUid(strlen($this->uid)); | ||
} | ||
|
||
private function generateUid($length) | ||
{ | ||
return substr(hash('md5', uniqid('', true)), 0, $length); | ||
} | ||
} |
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 | ||
|
||
/* | ||
* This file is part of the Monolog package. | ||
* | ||
* (c) Jordi Boggiano <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Monolog; | ||
|
||
/** | ||
* Handler or Processor implementing this interface will be reset when Logger::reset() is called. | ||
* | ||
* Resetting an Handler or a Processor usually means cleaning all buffers or | ||
* resetting in its internal state. | ||
* | ||
* @author Grégoire Pineau <[email protected]> | ||
*/ | ||
interface ResettableInterface | ||
{ | ||
public function reset(); | ||
} |
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
Oops, something went wrong.