定制 yiier/yii2-graylog-target 二次开发

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

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

yiier/yii2-graylog-target

Composer 安装命令:

composer require yiier/yii2-graylog-target

包简介

Graylog log target for Yii2

README 文档

README

Graylog log target for Yii2

Latest Stable Version Total Downloads Latest Unstable Version License

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist yiier/yii2-graylog-target "*"

or add

"yiier/yii2-graylog-target": "*"

to the require section of your composer.json file.

Configuration

return [
    'components' => [
        'log' => [
            'targets' => [
                'graylog' => [
                    'class' => yiier\graylog\Target::class,
                    'levels' => ['error', 'warning', 'info'],
                    // 'categories' => ['application', 'graylog'],
                    // 'logVars' => ['_GET', '_POST', '_FILES', '_COOKIE', '_SESSION'],
                    // 'facility' => 'facility-name',
                    'transport' => [
                        'class' => yiier\graylog\transport\UdpTransport::class,
                        'host' => '127.0.0.1',
                        'port' => '1231',
                        'chunkSize' => 4321,
                    ],
                    'additionalFields' => [
                        'user-ip' => function ($yii) {
                            return ($yii instanceof \yii\console\Application) ? '' : $yii->request->userIP;
                        },
                        'tag' => 'tag-name'
                    ],
                ],
            ],
        ],
    ],
];

Transport

UDP transport

$transport = new yiier\graylog\transport\UdpTransport([
    // Host name or IP. Default to 127.0.0.1
    'host' => 'graylog.example.org',
    // UDP port. Default to 12201
    'port' => 1234,
    // UDP chunk size. Default to 8154
    'chunkSize' => 4321,
]);

TCP transport

$transport = new yiier\graylog\transport\UdpTransport([
    // Host name or IP. Default to 127.0.0.1
    'host' => 'graylog.example.org',
    // TCP port. Default to 12201
    'port' => 12201,
    // SSL options. (optional)
    'sslOptions' => [
        // Default to true
        'verifyPeer' => false,
        // Default to false
        'allowSelfSigned' => true,
        // Default to null
        'caFile' => '/path/to/ca.file',
        // Default to null
        'ciphers' => 'TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256',
    ],
]);

HTTP transport

$transport = new yiier\graylog\transport\HttpTransport([
    // Host name or IP. Default to 127.0.0.1
    'host' => 'graylog.example.org',
    // HTTP port. Default to 12202
    'port' => 12202,
    // Query path. Default to /gelf
    'path' => '/my/custom/greylog',
    // SSL options. (optional)
    'sslOptions' => [
        // Default to true
        'verifyPeer' => false,
        // Default to false
        'allowSelfSigned' => true,
        // Default to null
        'caFile' => '/path/to/ca.file',
        // Default to null
        'ciphers' => 'TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256',
    ],
]);

Usage

Once the extension is installed, simply use it in your code by :

Use \yiier\graylog\Log::info

<?php
\yiier\graylog\Log::info(
    'Test short message',
    'Test full message'
);


\yiier\graylog\Log::info(
    'Test short message',
    'Test full message', 
    [
        'additional1' => 'abc',
        'additional2' => 'def',
    ],
    'graylog'
);

Use Yii::info

<?php
// short_message will contain string representation of ['test1' => 123, 'test2' => 456],
// no full_message will be sent
Yii::info([
    'test1' => 123,
    'test2' => 456,
]);

// short_message will contain 'Test short message',
// two additional fields will be sent,
// full_message will contain all other stuff without 'short' and 'additional':
// string representation of ['test1' => 123, 'test2' => 456]
Yii::info([
    'test1' => 123,
    'test2' => 456,
    'short' => 'Test short message',
    'additional' => [
        'additional1' => 'abc',
        'additional2' => 'def',
    ],
]);
 
// short_message will contain 'Test short message',
// two additional fields will be sent,
// full_message will contain 'Test full message', all other stuff will be lost
Yii::info([
    'test1' => 123,
    'test2' => 456,
    'short' => 'Test short message',
    'full' => 'Test full message',
    'additional' => [
        'additional1' => 'abc',
        'additional2' => 'def',
    ],
]);

Reference

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2020-03-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固