yoannrenard/inline-logger

直接将日志输出到标准输出!

1.0.0 2017-02-13 15:24 UTC

This package is auto-updated.

Last update: 2024-09-10 03:16:23 UTC


README

直接将日志输出到标准输出!

安装

使用Composer并运行

$> composer require yoannrenard/inline-logger

要求

示例

use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;

class RandomClass
{
    /** @var LoggerInterface */
    protected $logger;

    /**
     * @param LoggerInterface $logger
     */
    public function __construct(LoggerInterface $logger = null)
    {
        $this->logger = $logger ?: new NullLogger();
    }

    public function randomMethod()
    {
        $this->logger->info('My random log');
    }
}

在生产环境中运行时,应始终将LoggerInterface注入RandomClass类。

但假设你想出于某种原因,在不使用Monolog,也不使用任何J的情况下,在模拟命令行中玩玩。

$randomClass = new RandomClass(new InlineLogger());
$randomClass->randomMethod();

这个模拟的InlineLogger类会打印出你所有的亲爱日志到你的标准输出

[2017-02-13 16:07:30] php.INFO: My random log