kba-team/cakephp-graylog

CakePHP 的 Graylog 引擎

安装次数: 24,619

依赖项: 0

建议者: 0

安全: 0

星标: 0

关注者: 3

分支: 5

开放问题: 1

类型:cakephp-plugin

v4.0.1 2024-08-22 07:05 UTC

README

License: MIT Packagist Version Build Status Maintainability Test Coverage

CakePHP 3.x 的 Graylog 日志引擎

使用方法

composer require kba-team/cakephp-graylog
<?php
\Cake\Core\Configure::write('Log.graylog', [
    'className' => \kbATeam\CakePhpGraylog\Log\Engine\GraylogLog::class,
    'levels' => [\Psr\Log\LogLevel::EMERGENCY, \Psr\Log\LogLevel::ALERT, \Psr\Log\LogLevel::CRITICAL],
    'host' => 'graylog.example.com',
    'port' => 12201,
    'scheme' => 'udp',
    'facility' => 'MyAppName',
    'append_backtrace' => true,
    'append' => [
        //append the contents of $_POST JSON encoded to the message body
        'POST' => static function () {
             if (!empty($_POST)) {
                $obfuscator = new \kbATeam\GraylogUtilities\Obfuscator();
                //Replace the value of all keys named 'password' with 'xxx'.
                $obfuscator->addKey('password');
                $obfuscator->setObfuscationString('xxx');
                //JSON encode the POST variable for readability.
                return json_encode(
                    $obfuscator->obfuscate($_POST),
                    JSON_PRETTY_PRINT
                );
             }
             return null;
        }
    ],
    'additional' => [
        //Add field 'current_user' to the GELF message.
        'current_user' => static function () {
             return AuthComponent::user('username');
        }
    ]
]);

可能的配置参数包括

  • scheme 目前支持 TCP 或 UDP 连接到 Graylog。默认:udp
  • host Graylog 服务器的主机名。默认:127.0.0.1
  • port Graylog 服务器监听的端口。默认:12201
  • url 格式为 <scheme>://<host>:<port> 的连接 URL。这将覆盖其他所有设置。
  • ignore_transport_errors 忽略传输错误。默认:true
  • chunk_size UDP 数据包的大小。默认:\Gelf\Transport\UdpTransport::CHUNK_SIZE_LAN
  • ssl_options 一个 \Gelf\Transport\SslOptions 的实例,用于定义 TCP 连接的 SSL 设置。默认:null
  • facility 记录设施。默认:CakePHP
  • append_backtrace 将回溯附加到消息?默认:true
  • append 匿名函数的数组(实际上可以是任何 is_callable() 的东西)。它们的返回字符串被附加到消息体中。
  • additional 匿名函数的数组(实际上可以是任何 is_callable() 的东西)。它们的返回值被添加为 GELF 消息的附加字段。
  • levels 将发送到 Graylog 的日志级别的数组。有关所有可能的值,请参阅 \Psr\Log\LogLevel。默认:所有。

进一步阅读