ankit-twidpay / twid-logger
用于在项目间保持一致日志记录的集中式日志包。
0.0.7
2023-10-01 17:46 UTC
Requires
- php: ^8.0
- illuminate/support: ^8.0
- monolog/monolog: ^2.5
Requires (Dev)
- phpunit/phpunit: ^9.0
This package is not auto-updated.
Last update: 2024-09-29 22:28:24 UTC
README
用于在项目间保持一致日志记录的集中式日志包。
安装
您可以通过Composer安装此包
composer require ankit-twidpay/twid-logger
配置
使用以下 artisan 命令发布配置文件
php artisan vendor:publish --tag=config
这将在您的 config
目录中创建一个 logging.php
文件。您可以自定义此文件以定义日志通道、元数据和掩码字段。
Laravel 配置
别名
将以下别名添加到您的 config/app.php
文件中的 aliases 数组
'TLog' => twid\logger\Facades\TLog::class,
服务提供者
将以下服务提供者添加到您的 config/app.php
文件中的 providers 数组
twid\logger\TwidLoggerServiceProvider::class,
Lumen 配置
别名
打开您的 bootstrap/app.php
文件并添加以下别名
class_alias('twid\logger\Facades\TLog', 'TLog');
服务提供者
打开您的 bootstrap/app.php
文件并注册服务提供者
$app->register(twid\logger\TwidLoggerServiceProvider::class);
使用方法
门面:TLog
此包提供了一个名为 TLog
的门面,用于记录消息。您可以使用此门面动态地将消息记录到不同的通道。
示例
use twid\logger\Facades\TLog; // Log an information message to the 'default' channel TLog::info('This is an information message'); // Log an error message to the 'error' channel TLog::error('This is an error message', ['error_code' => 500]);
如果您使用一个通道名称作为方法,门面将消息记录到该通道。如果方法没有明确定义,它被视为通道名称,并且将在相应的日志记录实例上调用日志方法。
日志记录器
Logger
类负责处理日志消息。它使用日志通道初始化,您可以使用它记录带特定数据的消息。
示例
use twid\logger\Logger; // Create a logger instance for the 'info' channel $logger = new Logger('info'); // Log a message with additional data $logger->log('This is a log message', ['user_id' => 123]);
许可证
此包是开源软件,受 MIT 许可证的许可。