muchrm/laravel-graylog 问题修复 & 功能扩展

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

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

muchrm/laravel-graylog

Composer 安装命令:

composer require muchrm/laravel-graylog

包简介

Log your Laravel application errors to Graylog

README 文档

README

##Notic This is forcked version of swisnl/laravel-graylog2 i'm using it on my project Don't use me yet.

Graylog Logging for Laravel 5.x

Latest Stable Version Build Status

Installation

  1. Run composer require for this package: composer require muchrm/laravel-graylog
  2. Add the service provider to app.php if you don't like auto discovery: Muchrm\Graylog\GraylogServiceProvider
  3. Run php artisan vendor:publish to publish the config file to ./config/graylog.php.
  4. Configure it to your liking
  5. Done!

Logging exceptions

The default settings enable logging of exceptions. It will add the HTTP request to the GELF message, but it will not add POST values. Check the graylog2.log-requests config to enable or disable this behavior.

Message Processors

Processors add extra functionality to the handler. You can register processors by modifying the AppServiceProvider:

public function register()
{
    //...
    Graylog::registerProcessor(new \Muchrm\Graylog\Processor\ExceptionProcessor());
    Graylog::registerProcessor(new \Muchrm\Graylog\Processor\RequestProcessor());
    Graylog::registerProcessor(new MyCustomProcessor());
    //...
}

The following processors are available by default:

ExceptionProcessor

Adds exception data to the message if there is any.

RequestProcessor

Adds the current Laravel Request to the message. It adds the url, method and ip by default.

Custom processors

You can define a custom processor by implementing Muchrm\Graylog\Processor\ProcessorInterface. The result should look something like this:

<?php

namespace App\Processors;

use Auth;
use Muchrm\Graylog\Processor\ProcessorInterface;

class MyCustomProcessor implements ProcessorInterface
{
    public function process($message, $exception, $context)
    {
        $message->setAdditional('domain', config('app.url'));

        if (Auth::user()) {
            $message->setAdditional('user_id', Auth::id());
        }

        return $message;
    }
}

Don't report exceptions

In app/Exceptions/Handler.php you can define the $dontReport array with Exception classes that won't be reported to the logger. For example, you can blacklist the \Illuminate\Database\Eloquent\ModelNotFoundException. Check the Laravel Documentation about errors for more information.

Logging arbitrary data

You can instantiate the Graylog class to send additional GELF messages:

// Send default log message
Graylog::log('emergency', 'Dear Sir/Madam, Fire! Fire! Help me!. 123 Cavendon Road. Looking forward to hearing from you. Yours truly, Maurice Moss.', ['facility' => 'ICT']);

// Send custom GELF Message
$message = new \Gelf\Message();
$message->setLevel('emergency');
$message->setShortMessage('Fire! Fire! Help me!');
$message->setFullMessage('Dear Sir/Madam, Fire! Fire! Help me!. 123 Cavendon Road. Looking forward to hearing from you. Yours truly, Maurice Moss.');
$message->setFacility('ICT');
$message->setAdditional('employee', 'Maurice Moss');
Graylog::logMessage($message);

Troubleshooting

Long messages (or exceptions) won't show up in Graylog

You might need to increase the size of the UDP chunks in the UDP Transport (see the config file). Otherwise, you can send packets in TCP mode.

统计信息

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

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 6
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-03-27

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固