68 lines
1.2 KiB
PHP
68 lines
1.2 KiB
PHP
|
<?php
|
||
|
/**
|
||
|
* Banker
|
||
|
*
|
||
|
* A Caching library implementing psr/cache
|
||
|
*
|
||
|
* PHP version 5.6
|
||
|
*
|
||
|
* @package Banker
|
||
|
* @author Timothy J. Warren <tim@timshomepage.net>
|
||
|
* @copyright 2016 Timothy J. Warren
|
||
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||
|
* @version 1.0.0
|
||
|
* @link https://git.timshomepage.net/timw4mail/banker
|
||
|
*/
|
||
|
|
||
|
namespace Aviat\Banker;
|
||
|
|
||
|
use Psr\Log\LoggerInterface;
|
||
|
use Psr\Log\LogLevel;
|
||
|
use Psr\Log\NullLogger;
|
||
|
|
||
|
/**
|
||
|
* Trait for keeping track of logger objects
|
||
|
*/
|
||
|
trait LoggerTrait {
|
||
|
|
||
|
/**
|
||
|
* Logger instance to use
|
||
|
*
|
||
|
* @var LoggerInterface
|
||
|
*/
|
||
|
protected $logger = NULL;
|
||
|
|
||
|
/**
|
||
|
* Return the existing logger instance or
|
||
|
* a NullLogger, if no instance set
|
||
|
*
|
||
|
* @return LoggerInterface
|
||
|
*/
|
||
|
protected function getLogger()
|
||
|
{
|
||
|
if ($this->logger === NULL)
|
||
|
{
|
||
|
$this->logger = new NullLogger();
|
||
|
}
|
||
|
return $this->logger;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Set a logger to keep track of errors
|
||
|
*
|
||
|
* @param LoggerInterface $logger
|
||
|
* @return self
|
||
|
*/
|
||
|
public function setLogger(LoggerInterface $logger)
|
||
|
{
|
||
|
$this->logger = $logger;
|
||
|
|
||
|
// Set the logger for the current driver too
|
||
|
if (isset($this->driver))
|
||
|
{
|
||
|
$this->driver->setLogger($logger);
|
||
|
}
|
||
|
|
||
|
return $this;
|
||
|
}
|
||
|
}
|