yii2-extended/yii2-psr3-logger-bridge

一个用于连接psr-3日志记录器与yii日志系统的库

7.0.7 2024-07-31 13:26 UTC

README

一个用于连接psr-3日志记录器与yii日志系统的库

coverage build status

安装

此库的安装是通过composer完成的,并且通过其自动加载器加载此库的所有类。

  • 官方网站下载composer.phar
  • 然后运行以下命令将此库作为依赖项安装
  • php composer.phar yii2-extended/yii2-psr3-logger-bridge ^7

基本用法

此库提供了一个psr3兼容的日志记录器,用于将消息记录回yii2日志系统。由于Yii2的日志级别有限,此记录器将尝试使用提供的psr3级别的最接近的Yii2等效级别。

如果您正在寻找相反的(将日志记录到psr3兼容目标的yii2记录器),请查看官方的yii2-psr-log-target

Psr3ToYii2Logger的使用非常简单,只需查看PSR-3文档

通过此记录器记录的任何消息都将传输到Yii的应用程序log组件。


use Yii2Extended\Yii2Log\Psr3ToYii2Logger;
use Psr\Log\LogLevel;
use yii\log\Logger;

$logger = new Psr3ToYii2Logger();
// with the psr3 methods
$logger->emergency('A psr3 emergency message, logged as Yii2 error message');
// with the psr3 log levels
$logger->log(LogLevel::ALERT, 'A psr3 alert message, logged as Yii2 error message');
// with the yii2 log levels
$logger->log(Logger::LEVEL_PROFILE_BEGIN, 'A yii2 profile begin message, logged as profile begin message');

请注意,通过此组件传递的消息可能在$context数组中使用可选的__category____language__键。这将在需要时很有用,以确定日志消息的类别以及它应该翻译成哪种语言(因为yii的翻译会将消息与上下文合并并尝试使用Yii::t()方法进行翻译)。

许可证

MIT(见许可证文件)。