Skip to content

Instantly share code, notes, and snippets.

@g-alonso
Created December 21, 2015 18:24
Show Gist options
  • Save g-alonso/ebe89f4a5c906461afde to your computer and use it in GitHub Desktop.
Save g-alonso/ebe89f4a5c906461afde to your computer and use it in GitHub Desktop.
PHP Logging Trait
<?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