natural-cloud/logger-php
Composer 安装命令:
composer require natural-cloud/logger-php
包简介
quick into php framework
README 文档
README
介绍
借鉴和迁移修改 laravel 和 hyperf 对 monolog/monolog 封装,尽量达到快速接入任一 php 框架
接入
easyswoole
复制 config 到 dev.php
storage_path = sys_get_temp_dir(); return [ /* |-------------------------------------------------------------------------- | Default Log Channel |-------------------------------------------------------------------------- | | This option defines the default log channel that gets used when writing | messages to the logs. The name specified in this option should match | one of the channels defined in the "channels" configuration array. | */ // 'default' => env('LOG_CHANNEL', 'stack'), 'default' => 'stack', 'storage_path' => $storage_path,// 日志主目录, /* |-------------------------------------------------------------------------- | Deprecations Log Channel |-------------------------------------------------------------------------- | | This option controls the log channel that should be used to log warnings | regarding deprecated PHP and library features. This allows you to get | your application ready for upcoming major versions of dependencies. | */ 'deprecations' => 'LOG_DEPRECATIONS_CHANNEL', /* |-------------------------------------------------------------------------- | Log Channels |-------------------------------------------------------------------------- | | Here you may configure the log channels for your application. Out of | the box, Laravel uses the Monolog PHP logging library. This gives | you a variety of powerful log handlers / formatters to utilize. | | Available Drivers: "single", "daily", "slack", "syslog", | "errorlog", "monolog", | "custom", "stack" | */ 'channels' => [ 'stack' => [ 'driver' => 'stack', 'channels' => ['single'], 'ignore_exceptions' => false, ], 'single' => [ 'driver' => 'single', 'path' => 'single.log', // 日志文件路径 ,绝对路径, storage_path 设置可设置相对路径 'level' => 'debug', ], 'daily' => [ 'driver' => 'daily', 'path' => 'daily.log', // 日志文件路径 ,绝对路径, storage_path 设置可设置相对路径 'level' => 'debug', 'days' => 14, ], 'syslog' => [ 'driver' => 'syslog', 'level' => 'debug', ], 'errorlog' => [ 'driver' => 'errorlog', 'level' => 'debug', ], 'emergency' => [ 'driver' => 'single', 'path' => 'emergency.log', // 日志文件路径 ,绝对路径, storage_path 设置可设置相对路径 ], // 终端打印日志 'console' => [ 'name' => 'console', // 显示的名字 'driver' => 'monolog', 'level' => 'debug', 'handler' => StreamHandler::class, 'formatter' => \NaturalCloud\Logger\Formatter\ConsoleColorFormatter::class, 'with' => [ // handler 参数 'stream' => STDOUT, ], 'formatter_with' => [ // formatter 的构造函数参数 'dateFormat' => 'Y-m-d H:i:s' ], 'tap' => [\NaturalCloud\Logger\Tap\TapFormatter::class] ], 'json' => [ 'driver' => 'monolog', 'level' => 'debug', 'handler' => StreamHandler::class, 'with' => [ // handler 参数 'stream' => $storage_path . '/json.log', ], 'formatter' => \NaturalCloud\Logger\Formatter\JsonFormatter::class, 'formatter_with' => [ // formatter 的构造函数参数 'dateFormat' => 'Y-m-d H:i:s' ], 'tap' => [\NaturalCloud\Logger\Tap\TapFormatter::class] ] ], ];
注入 Di 容器
$loggerConfig = []; \NaturalCloud\Logger\Framework\Easyswoole::setLogger($loggerConfig,'logger-new')
获取 logger
$logger = \NaturalCloud\Logger\Framework\Easyswoole::getLogger('logger-new'); // 写到默认 chanel $logger->info('aaaa'); $logger->warning('bbbb'); // 打印到终端 info 级别 $logger->channel('console')->info('in console'); // 快速自定义配置logger ,用于动态的写入不同文件名的logger // 写入 日志主目录/swoole.log $logger->channelFile('swoole');
设置 traceId
\NaturalCloud\Logger\Framework\Easyswoole::trace($request,$response,'x-request-id',function (){ return \NaturalCloud\Logger\Support\Str::random('36') });
natural-cloud/logger-php 适用场景与选型建议
natural-cloud/logger-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6 次下载、GitHub Stars 达 1, 最近一次更新时间为 2023 年 02 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「logger」 「laravel」 「hyperf」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 natural-cloud/logger-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 natural-cloud/logger-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 natural-cloud/logger-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Workflow logger
HTTP request logger middleware for Laravel
High-performance, zero-dependency PSR-3 logger for MonkeysLegion with structured logging, handlers, processors, and PHP 8.4 features.
Logging http requests and errors
Logger classes (currently supports file system, console and simple email logging), part of QuEasy PHP Framework
Alfabank REST API integration
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-02-02