-
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 #8 from polderknowledge/feature/daily-stream
Feature/daily stream
- Loading branch information
Showing
2 changed files
with
71 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
/** | ||
* Polder Knowledge / log-module (https://polderknowledge.com) | ||
* | ||
* @link https://github.com/polderknowledge/log-module for the canonical source repository | ||
* @copyright Copyright (c) 2016-2017 Polder Knowledge (https://polderknowledge.com) | ||
* @license https://github.com/polderknowledge/log-module/blob/master/LICENSE.md MIT | ||
*/ | ||
|
||
namespace PolderKnowledge\LogModule\Monolog\Handler\Factory; | ||
|
||
use Monolog\Handler\StreamHandler; | ||
use Monolog\Logger; | ||
use WShafer\PSR11MonoLog\FactoryInterface; | ||
|
||
final class DailyStream implements FactoryInterface | ||
{ | ||
public function __invoke(array $options) | ||
{ | ||
$stream = $this->getStream( | ||
$options['stream'] ?? null, | ||
$options['dateFormat'] ?? 'Ymd' | ||
); | ||
|
||
$level = (int)($options['level'] ?? Logger::DEBUG); | ||
$bubble = (boolean)($options['bubble'] ?? true); | ||
$filePermission = (int)($options['filePermission'] ?? 0644); | ||
$useLocking = (boolean)($options['useLocking'] ?? true); | ||
|
||
return new StreamHandler($stream, $level, $bubble, $filePermission, $useLocking); | ||
} | ||
|
||
protected function getStream($stream, $dateFormat) | ||
{ | ||
if (is_resource($stream)) { | ||
return $stream; | ||
} | ||
|
||
return sprintf((string)$stream, date($dateFormat)); | ||
} | ||
} |
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,30 @@ | ||
<?php | ||
/** | ||
* Polder Knowledge / log-module (https://polderknowledge.com) | ||
* | ||
* @link https://github.com/polderknowledge/log-module for the canonical source repository | ||
* @copyright Copyright (c) 2016-2017 Polder Knowledge (https://polderknowledge.com) | ||
* @license https://github.com/polderknowledge/log-module/blob/master/LICENSE.md MIT | ||
*/ | ||
|
||
namespace PolderKnowledge\LogModule\Monolog\Handler\Factory; | ||
|
||
use Monolog\Handler\StreamHandler; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class DailyStreamTest extends TestCase | ||
{ | ||
public function testInvoke() | ||
{ | ||
// Arrange | ||
$options = []; | ||
|
||
$factory = new DailyStream(); | ||
|
||
// Act | ||
$result = $factory->__invoke($options); | ||
|
||
// Assert | ||
static::assertInstanceOf(StreamHandler::class, $result); | ||
} | ||
} |