定制 anik/loguzz 二次开发

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

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

anik/loguzz

Composer 安装命令:

composer require anik/loguzz

包简介

Loguzz is a guzzlehttp/guzzle request & response logger

README 文档

README

Loguzz codecov Total Downloads Latest Stable Version

Loguzz is a middleware for Guzzle which logs requests and responses.

Installation

You'll need composer to install the package. composer require anik/loguzz

Documentation V1

Find the thorough documentation here.

Documentation V4/V3/V2

To log a request, you'll need to push Loguzz\Middleware\LogMiddleware to Guzzle's handler.

$logger = new \ColinODell\PsrTestLogger\TestLogger();
$handlerStack = \GuzzleHttp\HandlerStack::create();
$options = [];
$handlerStack->push(new \Loguzz\Middleware\LogMiddleware($logger, $options), 'logger');
  • $logger is the implementation of Psr\Log\LoggerInterface.
  • $options is an array to change the default behaviour of LogMiddleware.
  • 'logger' is the internal name of the middleware for Guzzle. It can be any name.

Options

// Default values
$options = [
    'length' => 100,
    'log_request' => true,
    'log_response' => true,
    'success_only' => false,
    'exceptions_only' => false,
    'log_level' => 'debug',
    'request_formatter' => new \Loguzz\Formatter\RequestCurlFormatter(),
    'response_formatter' => new \Loguzz\Formatter\ResponseJsonFormatter(),
    'exception_formatter' => new \Loguzz\Formatter\ExceptionJsonFormatter(),
    'tag' => '',
    'force_json' => true,
    'separate' => false,
];
  • length - int. Minimum 10. To set the length of when formatting request with \Loguzz\Formatter\RequestCurlFormatter.
  • log_request - bool. To enable or disable request logging.
  • log_response - bool. To enable or disable response logging.
  • success_only - bool. Only log successful responses. If the server could be reached, it's a success.
  • exception_only - bool Only log exceptions. Logs when an exception is thrown by Guzzle for connection/timeout related exceptions.
  • log_level - string. Any valid log level.
  • request_formatter - instance of \Loguzz\Formatter\AbstractRequestFormatter. Available
    • \Loguzz\Formatter\RequestArrayFormatter
    • \Loguzz\Formatter\RequestCurlFormatter
    • \Loguzz\Formatter\RequestJsonFormatter
  • response_formatter - instance of \Loguzz\Formatter\AbstractResponseFormatter
    • \Loguzz\Formatter\ResponseArrayFormatter
    • \Loguzz\Formatter\ResponseJsonFormatter
  • exception_formatter - instance of \Loguzz\Formatter\AbstractResponseFormatter
    • \Loguzz\Formatter\ExceptionArrayFormatter
    • \Loguzz\Formatter\ExceptionJsonFormatter
  • tag - string. Empty by default. When non-empty string, it'll log the formatted data under this tag. Tag can be used to search for specific type of request/response in your log file or your storage.
  • force_json - bool. true by default. It is only applicable when tag is non-empty string. If enabled, it will then log data as json string, otherwise it'll log as an array. If set to false, the code may break due to the type-hint in psr/log interface. If your logger interface supports array, it will work.
  • separate - bool. It is only applicable when tag is non-empty string. If enabled, it will then log data in {tag}.request, {tag}.success, {tag}.failure for request logging, successful response and error response.

Request Formatter

To create a new request formatter you need to extend the \Loguzz\Formatter\AbstractRequestFormatter class.

Response Formatter

To create a new response formatter you need to extend the \Loguzz\Formatter\AbstractResponseFormatter class.

Exception Formatter

To create a new exception formatter you need to extend the \Loguzz\Formatter\AbstractExceptionFormatter class.

Manual Request formatting

Implementations of \Loguzz\Formatter\AbstractRequestFormatter::format accept parameters as

  • \Psr\Http\Message\RequestInterface $request
  • array $options = []

Available request formatters parse data from $request and cookies from the $options. The values in $options['cookies'] must be an implementation of \GuzzleHttp\Cookie\CookieJarInterface. To parse cookies, the request URL must contain the domain.

Manual Response formatting

Implementations of \Loguzz\Formatter\AbstractResponseFormatter::format accept parameters as

  • \Psr\Http\Message\RequestInterface $request
  • \Psr\Http\Message\ResponseInterface $response
  • array $options = []

Available response formatters parse data from $response and cookies from the set-cookie header. To parse cookies, the request URL must contain the domain.

The set-cookie headers will not be available in the headers for available response formatters.

Issues & PRs

If you think something is missing in the package or cause bug, please report an Issue. If you're available and want to contribute to the repository, please submit a PR.

anik/loguzz 适用场景与选型建议

anik/loguzz 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 229.3k 次下载、GitHub Stars 达 16, 最近一次更新时间为 2020 年 03 月 26 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 anik/loguzz 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 229.3k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 16
  • 点击次数: 22
  • 依赖项目数: 4
  • 推荐数: 0

GitHub 信息

  • Stars: 16
  • Watchers: 1
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-03-26