yoannrenard/inline-logger

Stdout your logs directly!

1.0.0 2017-02-13 15:24 UTC

This package is auto-updated.

Last update: 2024-04-10 02:32:31 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