本文整理汇总了PHP中Zend\Log\Logger::addWriter方法的典型用法代码示例。如果您正苦于以下问题:PHP Logger::addWriter方法的具体用法?PHP Logger::addWriter怎么用?PHP Logger::addWriter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Log\Logger
的用法示例。
在下文中一共展示了Logger::addWriter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getLogger
/**
* @param $log_path
* @return ZendLogger
*/
public static function getLogger($log_path)
{
if (!self::$logger) {
#region ディレクトリ生成
$date = date('Ym');
$error_dir = $log_path . 'error/' . $date . '/';
$info_dir = $log_path . 'info/' . $date . '/';
if (!file_exists($error_dir)) {
@mkdir($error_dir, 0777);
}
if (!file_exists($info_dir)) {
@mkdir($info_dir, 0777);
}
#endregion
#region log初期設定
$logger = new ZendLogger();
$writer_err = new Stream($error_dir . date('Y-m-d') . '.log');
$writer_info = new Stream($info_dir . date('Y-m-d') . '.log');
//エラーログの出力レベル変更
$filter = new Priority(ZendLogger::WARN);
$writer_err->addFilter($filter);
$logger->addWriter($writer_err);
$logger->addWriter($writer_info);
#endregion
self::$logger = $logger;
}
return self::$logger;
}
示例2: _getLogger
/**
* @param $sFile
* @param array $aOptions
*
* @return mixed
*/
protected function _getLogger($sFile, array $aOptions = [])
{
$sKey = md5($sFile);
if (!isset($this->_aLoggers[$sKey])) {
$aWriterConfig = $this->_aConfig['writer'];
$oLogger = new Logger($aOptions);
if (isset($aWriterConfig['file']['enabled']) && $aWriterConfig['file']['enabled']) {
$oFileWriter = $this->_getFileWriter($sFile);
if (is_object($oFileWriter)) {
$oLogger->addWriter($oFileWriter);
}
}
if (isset($aWriterConfig['mail']['enabled']) && $aWriterConfig['mail']['enabled']) {
$oMailWriter = $this->_getMailWriter();
if (is_object($oMailWriter)) {
$oLogger->addWriter($oMailWriter);
}
}
if (isset($aWriterConfig['graylog']['enabled']) && $aWriterConfig['graylog']['enabled']) {
$oGraylogWriter = $this->_getGraylogWriter($sFile);
if (is_object($oGraylogWriter)) {
$oLogger->addWriter($oGraylogWriter);
}
}
$this->_aLoggers[$sKey] = $oLogger;
}
return $this->_aLoggers[$sKey];
}
示例3: setUp
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
$this->stream = fopen('php://temp', 'r+');
$this->log = new Logger();
$this->log->addWriter(new Stream($this->stream));
$this->adapter = new Zf2LogAdapter($this->log);
}
示例4: setUp
public function setUp()
{
$this->writer = new \Zend\Log\Writer\Mock();
$this->logger = new \Zend\Log\Logger();
$this->logger->addWriter($this->writer);
$this->instance = new Response($this->logger);
}
示例5: createLogger
/**
*
*/
protected function createLogger()
{
$dirname = dirname($this->logFile);
if (!is_dir($dirname)) {
mkdir($dirname, 0755, true);
}
$this->logger = new Logger();
$this->logger->addWriter(new Stream($this->logFile));
}
示例6: initLogging
/**
* Init logging.
*
* @return void
*/
public function initLogging()
{
$writer = new Stream('php://output');
$this->logger = new Logger();
$this->logger->addWriter($writer);
$writer = new Stream('php://stderr');
$this->errLogger = new Logger();
$this->errLogger->addWriter($writer);
}
示例7: __construct
public function __construct(array $config, HttpClient $client)
{
$this->config = $config;
$this->http = $client;
// create file logger
$this->logger = new Logger();
$writer = new WriterStream(ROOT . '/data/log/wechat.log');
$this->logger->addWriter($writer);
$this->wechatUtil = new WechatUtil($this->logger, array('token' => $this->config['token'], 'encodingaeskey' => $this->config['EncodingAESKey'], 'appid' => $this->config['appid'], 'appsecret' => $this->config['secret'], 'logcallback' => $this->logger));
}
示例8: createService
/**
* @param \Zend\ServiceManager\ServiceLocatorInterface $sl
* @return \Zend\Log\Logger
*/
public function createService(ServiceLocatorInterface $sl)
{
if (!$this->logger) {
// Log to file
$this->logger = new \Zend\Log\Logger();
$writer = new \Zend\Log\Writer\Stream('logs/all.log');
$this->logger->addWriter($writer);
\Zend\Log\Logger::registerErrorHandler($this->logger, true);
}
return $this->logger;
}
示例9: setUp
protected function setUp()
{
$message = new MailMessage();
$transport = new Transport\File();
$options = new Transport\FileOptions(array('path' => __DIR__, 'callback' => function (Transport\File $transport) {
return MailTest::FILENAME;
}));
$transport->setOptions($options);
$this->writer = new MailWriter($message, $transport);
$this->log = new Logger();
$this->log->addWriter($this->writer);
}
示例10: __construct
public function __construct(ModuleOptions $options, ServiceLocatorInterface $serviceLocator)
{
$this->options = $options;
$this->serviceLocator = $serviceLocator;
if ($this->options->getLogDir()) {
$dirPath = $this->getLogDirPath($this->options->getLogDir());
$this->logger = new Logger();
$writer = new Stream($dirPath . '/mail.log');
$this->logger->addWriter($writer);
if (null !== $this->uMask) {
umask($this->uMask);
}
}
}
示例11: 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;
}
示例12: onBootstrap
public function onBootstrap(MvcEvent $e)
{
$events = StaticEventManager::getInstance();
$serviceManager = $e->getApplication()->getServiceManager();
$appConfig = $serviceManager->get('Config');
$logger = new Logger();
if (!isset($appConfig['operation_logger'])) {
throw new \RuntimeException("Logger not properly configured");
}
if (!isset($appConfig['operation_logger']['priority_filter'])) {
throw new \RuntimeException("You must specify a 'priority_filter' config param");
}
$logFilter = new PriorityFilter($appConfig['operation_logger']['priority_filter']);
if (!is_null($appConfig['operation_logger']['db_adapter'])) {
if (empty($appConfig['operation_logger']['logger_table'])) {
throw new \RuntimeException("You must specify a 'logger_table' config param");
}
$dbAdapter = $serviceManager->get($appConfig['operation_logger']['db_adapter']);
if (!$dbAdapter instanceof \Zend\Db\Adapter\Adapter) {
throw new \RuntimeException("Failed to load database adapter for logger");
}
$tableMapping = array('timestamp' => 'event_date', 'priorityName' => 'priority', 'message' => 'event', 'extra' => array('id_operation_log' => 'id_operation_log', 'note' => 'note', 'table' => 'table_name', 'id_user' => 'id_user', 'username' => 'username', 'id_row' => 'id_row', 'field' => 'field', 'value_old' => 'value_old', 'value_new' => 'value_new', 'source' => 'source', 'uri' => 'uri', 'ip' => 'ip', 'session_id' => 'session_id'));
$logWriter = new DbWriter($dbAdapter, $appConfig['operation_logger']['logger_table'], $tableMapping);
$logWriter->addFilter($logFilter);
$logger->addWriter($logWriter);
}
// nel caso si volgia fare un file LOG
if (isset($appConfig['operation_logger']['log_file']) && !is_null($appConfig['operation_logger']['log_file'])) {
$streamWriter = new StreamWriter($appConfig['operation_logger']['log_file']);
$streamWriter->addFilter($logFilter);
$logger->addWriter($streamWriter);
}
$request = $e->getApplication()->getRequest();
$remoteAddress = new RemoteAddress();
Logger::registerErrorHandler($logger, true);
Logger::registerExceptionHandler($logger);
// Attacco evento per trigger LOG! (evento: operation-log)
$events->attach("*", 'operation-log', function (\Zend\EventManager\Event $e) use($logger, $request, $remoteAddress, $serviceManager) {
$targetClass = get_class($e->getTarget());
$message = $e->getParam('message');
$priority = $e->getParam('priority', Logger::INFO);
$zfcAuthEvents = $serviceManager->get('zfcuser_auth_service');
$idUser = $zfcAuthEvents->hasIdentity() ? $zfcAuthEvents->getIdentity()->getId() : (array_key_exists('id_user', $message) ? $message['id_user'] : 'guest');
$displayName = $zfcAuthEvents->hasIdentity() ? $zfcAuthEvents->getIdentity()->getDisplayName() : (array_key_exists('username', $message) ? $message['username'] : 'guest');
$extras = array('id_operation_log' => null, 'note' => array_key_exists('note', $message) ? $message['note'] : null, 'table_name' => array_key_exists('table', $message) ? $message['table'] : null, 'operation' => array_key_exists('operation', $message) ? $message['operation'] : null, 'id_user' => $idUser, 'username' => $displayName, 'id_row' => array_key_exists('id_row', $message) ? $message['id_row'] : null, 'field' => array_key_exists('field', $message) ? $message['field'] : null, 'value_old' => array_key_exists('value_old', $message) ? $message['value_old'] : null, 'value_new' => array_key_exists('value_new', $message) ? $message['value_new'] : null, 'source' => $targetClass, 'uri' => $request->getUriString(), 'ip' => $remoteAddress->getIpAddress(), 'session_id' => session_id());
$logger->log($priority, $message['message'], $extras);
});
}
示例13: generateFileLogger
public static function generateFileLogger($logFile, $logDir)
{
$fileName = static::validateLogFile($logFile, $logDir);
$zendLogLogger = new Logger();
$zendLogLogger->addWriter(new Stream($fileName));
return new PsrLoggerAdapter($zendLogLogger);
}
示例14: createService
/**
* Create the NewRelic logger
*
* @param ServiceLocatorInterface $serviceLocator
* @return Logger
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
$logger = new Logger();
$writer = $serviceLocator->get('NewRelic\\Log\\Writer');
$logger->addWriter($writer);
return $logger;
}
示例15: get
/**
* Provide instance
*
* @return CacheAdapter
*/
public function get()
{
$logger = new Logger();
$writer = new Stream($this->logDir . '/app.log');
$logger->addWriter($writer);
return new Zf2LogAdapter($logger);
}