Created
December 21, 2015 18:24
-
-
Save g-alonso/ebe89f4a5c906461afde to your computer and use it in GitHub Desktop.
PHP Logging Trait
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Logging | |
*/ | |
namespace Galonso\Logging; | |
/** | |
* Logging trait | |
*/ | |
trait Logging | |
{ | |
/** | |
* @var \Psr\Log\LoggerInterface | |
*/ | |
protected $logger = null; | |
/** | |
* Set logger | |
* | |
* @param \Psr\Log\LoggerInterface $logger | |
* @return void | |
*/ | |
public function setLogger(\Psr\Log\LoggerInterface $logger) | |
{ | |
$this->logger = $logger; | |
} | |
/** | |
* Log something | |
* | |
* @param string $level | |
* @param string $msg | |
* @return void | |
*/ | |
protected function log($level, $msg) | |
{ | |
if ($this->logger !== null) { | |
$this->logger->{$level}($msg); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment