hedii/laravel-gelf-logger 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

hedii/laravel-gelf-logger

Composer 安装命令:

composer require hedii/laravel-gelf-logger

包简介

A Laravel package to send logs to a gelf compatible backend like graylog

README 文档

README

Build Status Total Downloads License Latest Stable Version

Laravel laravel-gelf-logger
5.6 ^3.0
5.8 ^3.1
6.0 ^4.0
7.0 ^5.0
8.0 ^5.3
8.0 ^6.0 (with php 8)
9.0 ^7.0
10.0 ^8.0
11.0 ^9.0
12.0 ^10.0
13.0 ^13.0

A package to send gelf logs to a gelf compatible backend like graylog. It is a Laravel wrapper for bzikarsky/gelf-php package.

It uses the new Laravel custom log channel introduced in Laravel 5.6.

A gelf receiver like graylog2 must be configured to receive messages with a GELF UDP, TCP or HTTP Input.

Table of contents

Installation

Install via composer

composer require hedii/laravel-gelf-logger

Edit config/logging.php to add the new gelf log channel.

return [
    'default' => env('LOG_CHANNEL', 'stack'),

    'channels' => [
        // You can use the gelf log channel with the stack log channel
        'stack' => [
            'driver' => 'stack',
            'channels' => ['daily', 'gelf'],
        ],

        // other log channels...

        'gelf' => [
            'driver' => 'custom',

            'via' => \Hedii\LaravelGelfLogger\GelfLoggerFactory::class,

            // This optional option determines the processors that should be
            // pushed to the handler. This option is useful to modify a field
            // in the log context (see NullStringProcessor), or to add extra
            // data. Each processor must be a callable or an object with an
            // __invoke method: see monolog documentation about processors.
            // Default is an empty array.
            'processors' => [
                \Hedii\LaravelGelfLogger\Processors\NullStringProcessor::class,
                \Hedii\LaravelGelfLogger\Processors\RenameIdFieldProcessor::class,
                // another processor...
            ],

            // This optional option determines the minimum "level" a message
            // must be in order to be logged by the channel. Default is 'debug'
            'level' => 'debug',

            // This optional option determines the channel name sent with the
            // message in the 'facility' field. Default is equal to app.env
            // configuration value
            'name' => 'my-custom-name',

            // This optional option determines the system name sent with the
            // message in the 'source' field. When forgotten or set to null,
            // the current hostname is used.
            'system_name' => null,

            // This optional option determines if you want the UDP, TCP or HTTP
            // transport for the gelf log messages. Default is UDP
            'transport' => 'udp',

            // This optional option determines the host that will receive the
            // gelf log messages. Default is 127.0.0.1
            'host' => '127.0.0.1',

            // This optional option determines the port on which the gelf
            // receiver host is listening. Default is 12201
            'port' => 12201,
            
            // This optional option determines the chunk size used when
            // transferring message via UDP transport. Default is 1420.
            'chunk_size' => 1420,

            // This optional option determines the path used for the HTTP
            // transport. When forgotten or set to null, default path '/gelf'
            // is used.
            'path' => null,
            
            // This optional option enable or disable ssl on TCP or HTTP
            // transports. Default is false.
            'ssl' => false,
            
            // If ssl is enabled, the following configuration is used.
            'ssl_options' => [
                // Enable or disable the peer certificate check. Default is
                // true.
                'verify_peer' => true,
                
                // Path to a custom CA file (eg: "/path/to/ca.pem"). Default
                // is null.
                'ca_file' => null,
                
                // List of ciphers the SSL layer may use, formatted as
                // specified in ciphers(1). Default is null.
                'ciphers' => null,
                
                // Whether self-signed certificates are allowed. Default is
                // false.
                'allow_self_signed' => false,
            ],
            
            // If you want to send messages to the gelf server using http basic
            // authentication, the following configuration is used. Only useful
            // if transport is set to http.
            'http_basic_auth' => [
                // The http basic authentication username.
                'username' => null,
                
                // The http basic authentication password.
                'password' => null,
            ],

            // This optional option determines the maximum length per message
            // field. When forgotten or set to null, the default value of 
            // \Monolog\Formatter\GelfMessageFormatter::DEFAULT_MAX_LENGTH is
            // used (currently this value is 32766)
            'max_length' => null,

            // This optional option determines the prefix for 'context' fields
            // from the Monolog record. Default is null (no context prefix)
            'context_prefix' => null,

            // This optional option determines the prefix for 'extra' fields
            // from the Monolog record. Default is null (no extra prefix)
            'extra_prefix' => null,
            
            // This optional option determines whether errors thrown during
            // logging should be ignored or not. Default is true.
            'ignore_error' => true,

        ],
    ],
];

Usage

Once you have modified the Laravel logging configuration, you can use the gelf log channel as any Laravel log channel.

Example

// Explicitly use the gelf channel
Log::channel('gelf')->debug($message, ['foo' => 'bar']);
Log::channel('gelf')->emergency($message, ['foo' => 'bar']);

// In case of a stack log channel containing the gelf log channel and stack
// configured as the default log channel
Log::notice($message, ['foo' => 'bar']);

// Using the logger helper
logger($message, $context);

Testing

composer test

License

laravel-gelf-logger is released under the MIT Licence. See the bundled LICENSE file for details.

hedii/laravel-gelf-logger 适用场景与选型建议

hedii/laravel-gelf-logger 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.62M 次下载、GitHub Stars 达 135, 最近一次更新时间为 2016 年 09 月 09 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「log」 「logging」 「php」 「laravel」 「udp」 「graylog2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 hedii/laravel-gelf-logger 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 hedii/laravel-gelf-logger 我们能提供哪些服务?
定制开发 / 二次开发

基于 hedii/laravel-gelf-logger 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 3.62M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 136
  • 点击次数: 30
  • 依赖项目数: 10
  • 推荐数: 0

GitHub 信息

  • Stars: 135
  • Watchers: 3
  • Forks: 33
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-09-09