定制 marco-introini/soap-logger 二次开发

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

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

marco-introini/soap-logger

Composer 安装命令:

composer require marco-introini/soap-logger

包简介

Simple PHP Soap logger

README 文档

README

Installation

Installation is possible using Composer

composer require marco-introini/soap-logger

Usage

Log

The main logger class can be instantiated using the following parameters:

  • a monolog handler
  • a line formatter
  • the name of the Soap service
  • the name of the method
  • if the request contains soapAction this information will be automatically added to logger
$handler = new RotatingFileHandler($_ENV['LOGFILE'], 3,Level::Info);
$formatter = new SplunkLineFormatter(allowInlineLineBreaks: true, quoteReplacement: "");

$soapLogger = new SoapLogger($handler,$formatter,"MyDemoService","demoMethodRead");

$soapLogger->log(file_get_contents('php://input'),Step::FROM_CALLER_TO_SERVICE);

Log SoapServer Request and Response XML

This is how to het the Soap envelope for request and response

Request

Obtaining request it's very easy:

$request = file_get_contents('php://input');
$soapLogger->log(file_get_contents('php://input'),Step::FROM_CALLER_TO_SERVICE);

Response

Obtaining response it's a bit more difficult. We must catch the output of the handle() method. Look at this example:

ob_start();
$server = new SoapServer("mywsdlfile.wsdl", array(
    'classmap' => array(
        'MyMethodResponse' => MyMethodResponse::class,
        'MyMethodRequest' => MyMethodRequest::class
    )
));
$server->addFunction("myMethod");
$server->handle();
$response = ob_get_contents();
ob_end_clean();
$soapLogger->log($response,Step::FROM_SERVICE_TO_CALLER);
echo $response;

In the $response variable we have the response XML.

Important: always remeber to echo the response!

Rotation based on file size

Very often the Soap log are very verbose, so it's useful to have a rotation method for Monolog to log rotation based on file size. This is not possible with plain Monolog. So I write a simple factory to generate a Monolog Handler which can do a log rotation.

The make factory accept these parameters:

  • logfile path
  • maximum size in bytes
  • number of files to rotate (will be kept these number of log-rotation)
  • log Level
$handler = RotateOnFileSizeHandler::make($_ENV['LOGFILE'],50000000,1,Level::Info);
$formatter = new SplunkLineFormatter(allowInlineLineBreaks: true, quoteReplacement: "");

$soapLogger = new SoapLogger($handler,$formatter,"MyDemoService","myMethod","myCorrelationId");

$soapLogger->log(file_get_contents('php://input'),Step::FROM_CALLER_TO_SERVICE);

Using standard Monolog Logger:

$handler = RotateOnFileSizeHandler::make($logfile, 1000, 1, Level::Info);

$logger = new Monolog\Logger($logTemp);
$logger->pushHandler($handler);

$logger->log(Level::Info,'log message');

Test

Tests are created using Pest

./vendor/bin/pest

License

This project is licensed as Open Source under MIT license

marco-introini/soap-logger 适用场景与选型建议

marco-introini/soap-logger 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.3k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 11 月 21 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-11-21