Last active
February 23, 2017 14:38
-
-
Save vasildakov-zz/c2886fc704c1a26ee591daae847b88eb to your computer and use it in GitHub Desktop.
Monolog and Handlers
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
<?php | |
# generic stream handler | |
use Monolog\Handler\StreamHandler; | |
class CustomStreamHandlerFactory | |
{ | |
public function __invoke(ContainerInterface $container) : StreamHandler | |
{ | |
$options = $container->get(CustomStreamHandlerOptions::class); | |
return new StreamHandler( | |
$options->getPath(), | |
$options->getLevel(), | |
$options->getBbubble() | |
); | |
} | |
} |
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
<?php | |
use Zend\Stdlib\AbstractOptions; | |
class CustomStreamHandlerOptions extends AbstractOptions | |
{ | |
/** | |
* @var string $path | |
*/ | |
protected $path; | |
/** | |
* @var int $level | |
*/ | |
protected $level; | |
/** | |
* @var string $bubble | |
*/ | |
protected $bubble; | |
public function setPath($path) | |
{ | |
$this->path = $path; | |
} | |
public function getPath() | |
{ | |
return $this->path; | |
} | |
public function setLevel($level) | |
{ | |
$this->level = $level; | |
} | |
public function getLevel() | |
{ | |
return $this->level; | |
} | |
public function setBubble($bubble) | |
{ | |
$this->bubble = $bubble; | |
} | |
public function getBubble() | |
{ | |
return $this->bubble; | |
} | |
} |
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
<?php | |
use Interop\Container\ContainerInterface; | |
use Zend\ServiceManager\Exception; | |
class CustomStreamHandlerOptionsFactory | |
{ | |
public function __invoke(ContainerInterface $container) | |
{ | |
$config = $container->get('config'); | |
$config['handler']['custom']['options']; | |
return new CustomStreamHandlerOptions($config); | |
} | |
} |
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
<?php | |
class ModuleConfig | |
{ | |
public function __invoke() | |
{ | |
return [ | |
'dependencies' => [ | |
'invokables' => [], | |
'factories' => [ | |
CustomStreamHandlerOptions::class => CustomStreamHandlerOptionsFactory::class, | |
CustomStreamHandler::class => CustomStreamHandlerFactory::class, | |
], | |
], | |
'loggers' => [ | |
CustomLogger::class => [ | |
'handlers' => [ | |
CustomStreamHandler::class | |
], | |
] | |
] | |
] | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment