Skip to content
/ log Public

LoggerAwareTrait implementation of the LoggerAwareInterface.

License

Notifications You must be signed in to change notification settings

simpliste/log

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

simpliste/log

Build Status Code Coverage Scrutinizer Code Quality Software License

LoggerAwareTrait implementation of the LoggerAwareInterface.

With the LoggerAwareTrait you can use log functions without knowing or the logger is set. When the logger is not set a NullLogger is returned so that the code does not break.

Installation

You can install simpliste log through Composer:

$ composer require simpliste/log

You can combine this LoggerAwareTrait with anything that implements the Psr\Log\LoggerInterface. For example Monolog can be used.

$ composer require monolog/monolog

Usage

<?php

use Monolog\Handler\Handler\StreamHandler;
use Monolog\Logger;
use Simpliste\Log\LoggerAwareTrait;
use Simpliste\Log\LoggerAwareInterface;

class Whoops implements LoggerAwareInterface
{
    use LoggerAwareTrait;
    
    public function run()
    {
        $this->getLogger()->info('Started running');
    }
}

echo 'Example without a logger set';
$whoops = new Whoops();
$whoops->run();

$logger = new Logger();
$logger->pushHandler(new StreamHandler('php://stdout', Logger::INFO));

echo 'Example with a logger set';
$whoopsWithLogger = new Whoops();
$whoopsWithLogger->setLogger($logger);

The above example will output:

Example without an logger set
Example with an logger set
Started running

About

LoggerAwareTrait implementation of the LoggerAwareInterface.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages