webzak/uzlog
Composer 安装命令:
composer require webzak/uzlog
包简介
Logging over udp
README 文档
README
Why
I had a need of something to debug the legacy projects with a quite unreadable code and complex data sructures. The idea is it should be very lightweight and have near zero impact on debugged application.
How it works
It sends the data over UDP protocol to recever: https://github.com/webzak/uzlog.
The data are sent over UDP without waiting for any confirmations from the receiver part. It works good on local machine and docker/local networks. I would not recommend to use it with open networks because the information is not encrypted.
Usage
use Webzak\Uzlog\{Socket, Transport, Log, Saver}; $socket = new Socket('127.0.0.1', 7000); $transport = new Transport($socket); $log = new Log($transport); $saver = new Saver($transport); $log->send("Hello"); $saver->send('servinfo.json', $_SERVER);
For practical use it is easier to create a global function somewhere in the common init:
use Webzak\Uzlog; #define UZL_HOST 127.0.0.1 #define UZL_PORT 7000 #define UZL_MAX_MSG_LEN 5000 function ulog($msg, array $opts = []) { static $client; if (!is_null($client)) { return $client->send($msg, $opts); } elseif ($msg instanceof \Udplog\Log) { $client = $msg; } } // init the instance ulog(new Uzlog\Log(new Uzlog\Transport(new Uzlog\Socket(UZL_HOST, UZL_PORT), ['limit' => UZL_MAX_MSG_LEN])); // then just use it anywhere ulog("Hello!", ['fg' => 21, 'bg' => 46]);
Init parameters
Socket
For socket the ip and port parameter must be set:
$socket = new Uzlog\Socket('172.17.0.1', 7777);
Transport
- max_packet - can be set for value between 21 and 508. By default it is set to 508 bytes.
$transport = new Uzlog\Transport($socket, ['max_packet' => 200]);
Log
-
limit (int) - limits the maximum size of single log message. If the message is longer than the limit, it's tail is cut and it it indicated like [10228->5000..]. This notation means that full message length was 10228 and it was cut to 5000. The option has internal default value = 500.
-
context (int) - if value is grater than 0, the calling context is added in front of log message. The greater the value the more deeper callstack is shown. By default it is disabled. Note that this value can be set personally per message, so may be applied only when you are really interested in calling stack investigation.
-
context_files (bool) - if true it additionally shows the filenames for callstack. By default it is disabled.
$log = new Uzlog\Log($transport, ['limit' => 2000, 'context' => 10]);
Saver
The saver has no init options.
$saver = new Uzlog\Saver($transport);
Logging options
-
fg (0-255) - message foreground color. It is sent as a one byte value with a message. See ANSI escape codes
-
bg (0-255) - message background color. It is sent as one byte value with a message.
-
limit (int) - overrides the global limit parameter for concrete message.
-
transform (string) - currently supports only 'json' value. If message is array, it is transformed to json string. (Else by default arrays are transformed with print_r($a,1))
-
context - overrided the global context parameter for concrete message.
-
prefix (string) - add prefix for message. This can be useful when message is a transformed structure.
$log->send($msg1); $log->send($msg2, ['fg' => 21, 'bg' => 46]); $log->send($msg3, ['limit' => 5000, 'context' => true]); $log->send($arr, ['transform' => 'json']); $log->send($arr, ['prefix' => 'ERR:']);
Saving options
- append - if true, the data is appended to file, by default it is overwritten.
- raw - do not prettify json, when saving arrays (arrays are automatically converted to json).
$saver->send('file.txt', 'somestring'); $saver->send('data.json', $array, ['raw' => true]); $saver->send('data.csv', $row, ['append' => true]);
Incremental filenames
The saver supports the special naming mode to generate the incremental filnames. This may be necessary when you are saving some data in loop. (The amount of '?' symbols determines the amount of digits).
foreach($x as $data) { $saver->send('data.???.json', $data); }
The results with be saved in files:
-
data.000.json
-
data.001.json
-
data.nnn.json
webzak/uzlog 适用场景与选型建议
webzak/uzlog 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 11 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「log」 「logging」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 webzak/uzlog 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 webzak/uzlog 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 webzak/uzlog 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Zend Framework module that sets up Monolog for logging in applications.
Asynchronous Sentry for Symfony - Fire and forget
Stackdriver handler for Monolog (codeinternetapplications/monolog-stackdriver Fork).
Laravel 5.x.x library for integration Monolog Sentry
High-performance, zero-dependency PSR-3 logger for MonkeysLegion with structured logging, handlers, processors, and PHP 8.4 features.
Pacote simplificado para persistência de logs
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-11-17