yoannrenard/inline-logger

This package is not installable via Composer 1.x, please make sure you upgrade to Composer 2+. Read more about our Composer 1.x deprecation policy.

Stdout your logs directly!

1.0.0 2017-02-13 15:24 UTC

This package is auto-updated.

Last update: 2021-06-09 20:29:09 UTC


README

Stdout your logs directly!

Installation

Use Composer and run :

$> composer require yoannrenard/inline-logger

Requirements

Example

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');
    }
}

A proper LoggerInterface should always be injected into the RandomClass class when running in production.

But imagine you wanna, for some reason, play with it in a dummy command line, without Monolog, without anything J

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

This dummy InlineLogger class will print in your stdout all your beloved logs

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