承接 guzzlehttp/log-subscriber 相关项目开发

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

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

guzzlehttp/log-subscriber

最新稳定版本:1.0.1

Composer 安装命令:

composer require guzzlehttp/log-subscriber

包简介

Logs HTTP requests and responses as they are sent over the wire (Guzzle 4+)

README 文档

README

The LogSubscriber logs HTTP requests and responses to a PSR-3 logger, callable, resource returned by fopen(), or by calling echo().

Here's the simplest example of how it's used:

use GuzzleHttp\Client;
use GuzzleHttp\Subscriber\Log\LogSubscriber;

$client = new Client();
$client->getEmitter()->attach(new LogSubscriber());
$client->get('http://httpbin.org');

Running the above example will echo a message using the Apache Common Log Format (CLF).

[info] hostname Guzzle/5.0 curl/7.21.4 PHP/5.5.7 - [2014-03-01T22:48:13+00:00] "GET / HTTP/1.1" 200 7641

Note

Because no logger is provided, the subscriber simply logs messages with echo(). This is the method used for logging if null is provided.

Installing

This project can be installed using Composer. Add the following to your composer.json:

{
    "require": {
        "guzzlehttp/log-subscriber": "~1.0"
    }
}

Using PSR-3 Loggers

You can provide a PSR-3 logger to the constructor as well. The following example shows how the LogSubscriber can be combined with Monolog.

use GuzzleHttp\Client;
use GuzzleHttp\Subscriber\Log\LogSubscriber;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;

// create a log channel
$log = new Logger('name');
$log->pushHandler(new StreamHandler('/path/to/your.log', Logger::WARNING));

$client = new Client();
$subscriber = new LogSubscriber($log);
$client->getEmitter()->attach($subscriber);

Logging with a custom message format

The LogSubscriber's constructor accepts a logger as the first argument and a message format string or a message formatter as the second argument. You could log the full HTTP request and Response message using the debug format via GuzzleHttp\Subscriber\Log\Formatter::DEBUG.

use GuzzleHttp\Subscriber\Log\LogSubscriber;
use GuzzleHttp\Subscriber\Log\Formatter;

// Log the full request and response messages using echo() calls.
$subscriber = new LogSubscriber(null, Formatter::DEBUG);

Message Formatter

Included in this repository is a message formatter. The message formatter is used to format log messages for both requests and responses using a log template that uses variable substitution for string enclosed in braces ({}).

The following variables are available in message formatter templates:

{request}
Full HTTP request message
{response}
Full HTTP response message
{ts}
Timestamp
{host}
Host of the request
{method}
Method of the request
{url}
URL of the request
{protocol}
Request protocol
{version}
Protocol version
{resource}
Resource of the request (path + query + fragment)
{hostname}
Hostname of the machine that sent the request
{code}
Status code of the response (if available)
{phrase}
Reason phrase of the response (if available)
{error}
Any error messages (if available)
{req_header_*}
Replace * with the lowercased name of a request header to add to the message.
{res_header_*}
Replace * with the lowercased name of a response header to add to the message
{req_headers}
Request headers as a string.
{res_headers}
Response headers as a string.
{req_body}
Request body as a string.
{res_body}
Response body as a string.

guzzlehttp/log-subscriber 适用场景与选型建议

guzzlehttp/log-subscriber 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.75M 次下载、GitHub Stars 达 41, 最近一次更新时间为 2026 年 01 月 04 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 guzzlehttp/log-subscriber 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 2.75M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 42
  • 点击次数: 29
  • 依赖项目数: 34
  • 推荐数: 2

GitHub 信息

  • Stars: 41
  • Watchers: 8
  • Forks: 10
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04