承接 xxxcoltxxx/request-logger 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

xxxcoltxxx/request-logger

Composer 安装命令:

composer require xxxcoltxxx/request-logger

包简介

Logging http requests and errors

README 文档

README

Build Status Latest Stable Version Total Downloads

This package allows sending request and response payload to the external logging system.

Supported out-of-box transports:

  • graylog transport for sending request log to Graylog server
  • log transport for sending request log to Laravel logging system
  • null transport for skip request log in application tests

Installation

Install via composer

composer require xxxcoltxxx/request-logger

Publish the configuration file

php artisan vendor:publish --provider="RequestLogger\RequestLoggerServiceProvider"

Add exception reporting to your app/Exception/Handler.php file

public function report(Exception $exception)
{
    request_logger()->setException($exception);

    // ...
    parent::report($exception);
}

Fill configuration

// Enable request logger for all requests without adds middleware
'all_routes' => true,

// Default transport
'default' => env('REQUEST_LOGGER_TRANSPORT', 'graylog'),

// The class for format log message
'formatter' => RequestLogger\RequestFormatter::class,

/*
 * Allowed transports with its configuration.
 * Drivers: 'graylog', 'log', 'null'
 */
'transports' => [

    // The graylog transport
    'graylog' => [
        // The Short message for graylog
        'short_message' => env('GRAYLOG_SHORT_MESSAGE', 'requests'),

        // Limit content size (in bytes). Set false to disable. Graylog has limitations on input messages
        'content_limit' => env('GRAYLOG_CONTENT_LIMIT', 30000),

        // The IP address of the log server
        'host' => env('GRAYLOG_HOST', '127.0.0.1'),

        // The UDP port of the log server
        'port' => env('GRAYLOG_PORT', '12201'),

        // The driver for send requests log to log server
        'driver' => RequestLogger\Transports\GelfUdpTransport::class,
    ],

    // ...
],

Adding app messages to request log

You can add custom messages to payload with request_logger helper.

request_logger()->addMessage('Full name: John Doe')

Enable logging only for specific routes

Request logger enabled on all routes by default. You can disable all_routes option in the configuration file and use request_logger middleware in routes configuration.

Documentation for registering middleware can be found in Laravel documentation

# config/request_logger.php

return [
    'all_routes' => false,

    // ...
];

# routes/api.php

Route::get('admin/profile', function () {
    //
})->middleware('request_logger');

Custom log format

For custom log format you can use closure in the configuration file:

# config/request_logger.php

return [
    // ...

    'formatter' => function () {
        $provider  = request_logger();
        $exception = $provider->getException();
        $request   = $provider->getRequest();
        $response  = $provider->getResponse();

        return [
            'uri'           => $request->getRequestUri(),
            'has_exception' => ! is_null($exception),
        ];
    }

    // ...

Writing custom drivers

For writing custom driver you must add driver configuration and implement RequestLogger\Transports\RequestLoggerTransport interface:

# .env

REQUEST_LOGGER_TRANSPORT=custom

# config/request_logger.php

return [
    // ...

    'transports' => [
        // ...

        'custom' => [
            'driver' => Namespace\CustomTransport::class,
            'custom_option' => 'value',
        ],
    ],
];

Disable request logger in application tests

Use null driver. You can use REQUEST_LOGGER_TRANSPORT variable in phpunit.xml configuration file.

Testing

composer install
vendor/bin/phpunit tests

Roadmap

  1. Unit tests
  2. Write Documentation for:
    • Custom log format
    • Writing custom drivers
  3. Add log driver
  4. Add null driver
  5. Add changelog
  6. Make video "How it works with graylog"

xxxcoltxxx/request-logger 适用场景与选型建议

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

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 10
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2018-09-08