定制 debugger84/zf2-graylog 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

debugger84/zf2-graylog

Composer 安装命令:

composer require debugger84/zf2-graylog

包简介

A Zend\Log writer and formatter helps you add Graylog logging to your ZF2 application.

README 文档

README

A Zend\Log writer and formatter helps you add Graylog logging to your ZF2 application, using bzikarsky/gelf-php: the newer version of deprecated Graylog2/gelf-php library.

Install

composer require debugger84/zf2-graylog:dev-master

Add values of graylog connection to your config

    'graylog' => [
        'host' => 'http://graylog.local',
        'port' => 12222,
        'facility' => 'Your project name'
    ],

Rewrite factory for Zend Logger interface

\Zend\Log\LoggerInterface::class => \ZF2Graylog\Factory\LoggerFactory::class,

Usage

I added a method to a custom base controller:

class Base extends \Zend\Mvc\Controller\AbstractActionController {
    private $logger;

    protected function getLogger() {
        if (!isset($this->logger)) {
            $this->logger = new \Zend\Log\Logger;

            // __construct($facility, $hostname, $port)
            $writer = new \ZF2Graylog\Log\Writer\Graylog2('ZF2', '127.0.0.1');
            $this->logger->addWriter($writer);
        }

        return $this->logger;
    }
}

Which can then be used as usual:

$this->getLogger()->info('Informative message');

The formatter should (or will) support error logging (as below) by mapping the following attributes to their respective GELF fields:

$logger = new \Zend\Log\Logger;
$writer = new \ZF2Graylog\Log\Writer\Graylog2('ZF2', '127.0.0.1');
$logger->addWriter($writer);

Zend\Log\Logger::registerErrorHandler($logger);


Zend\Log        GELFMessage
--------------------------------------------------------------------------------
message         message, full_message, short_message (unless present in $values)
errno           level
file            file
line            line
context         additional fields (to be tested)

Additional fields that are associated with GELF fields:

  • full (message) is mapped to full_message (if present, otherwise message)
  • short (message) is mapped to short_message (if present, otherwise message)
  • version is mapped to version (not set if not present)
  • facility is mapped to facility. A default facility is set in the writer.
  • Additional fields are mapped as additional fields.

Todo

  • Write a composer.json that includes the Graylog2/gelf-php lib.
  • Docblocks.
  • Further testing of different events.
  • Check errno maps to the correct severity level when used as an errorHandler.

License

TBC, will probably be MIT.

统计信息

  • 总下载量: 1.62k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-07-03

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固