本文整理汇总了PHP中Zend\Log\Logger::getWriters方法的典型用法代码示例。如果您正苦于以下问题:PHP Logger::getWriters方法的具体用法?PHP Logger::getWriters怎么用?PHP Logger::getWriters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Log\Logger
的用法示例。
在下文中一共展示了Logger::getWriters方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
public function setUp()
{
$logger = new Logger();
$writers = $logger->getWriters();
$this->writer = new LogWriter();
$writers->insert($this->writer, 1);
$this->listener = new ErrorListener($logger);
}
示例2: createService
/**
* {@inheritDoc}
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
// create new logger
$logger = new Logger();
// get application config as array
$config = $serviceLocator->get('config');
$config = $config['dherrorlogging'];
// get priority
$priority = Logger::WARN;
if (isset($config['priority']) && is_int($config['priority'])) {
$priority = $config['priority'];
}
$priorityFilter = new Filter\Priority($priority);
// get writers from config
if (!empty($config['log_writers']) && is_array($config['log_writers'])) {
$logWriterManager = $serviceLocator->get('LogWriterManager');
foreach ($config['log_writers'] as $writerSpecs) {
// skip if no name
if (empty($writerSpecs['name']) || !is_string($writerSpecs['name'])) {
continue;
}
// get options
$options = array();
if (!empty($writerSpecs['options']) && is_array($writerSpecs['options'])) {
$options = $writerSpecs['options'];
}
// check if it is one of the known writers that can be created via config or retrieved from service manager
if ($logWriterManager->has($writerSpecs['name'])) {
$writer = $logWriterManager->get($writerSpecs['name'], $options);
// add priority filter
$writer->addFilter($priorityFilter);
// add writer to logger
$logger->addWriter($writer);
}
}
}
// add processors which will add some extra helpful info (IP, URI, trace,..) to the final log.
$processor = $serviceLocator->get('LogProcessorManager')->get('DhErrorLogging\\LoggerProcessor');
$logger->addProcessor($processor);
// Logger needs at least one writer. Check if there are any, else add empty one.
if ($logger->getWriters()->count() == 0) {
// Support for PHP7 / Zend >= 2.4
if (class_exists('\\Zend\\Log\\Writer\\Noop')) {
$logger->addWriter(new Writer\Noop());
} else {
$logger->addWriter(new Writer\Null());
}
}
return $logger;
}
示例3: testOptionsWithWriterOptions
public function testOptionsWithWriterOptions()
{
$options = array('writers' => array(array('name' => 'stream', 'options' => array('stream' => 'php://output', 'log_separator' => 'foo'))));
$logger = new Logger($options);
$writers = $logger->getWriters()->toArray();
$this->assertCount(1, $writers);
$this->assertInstanceOf('Zend\\Log\\Writer\\Stream', $writers[0]);
$this->assertEquals('foo', $writers[0]->getLogSeparator());
}