Skip to content

Instantly share code, notes, and snippets.

@sokil
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sokil/56654a5abdfbcce411ea to your computer and use it in GitHub Desktop.
Save sokil/56654a5abdfbcce411ea to your computer and use it in GitHub Desktop.
Yii-PSR Log Adapter
<?php
use Psr\Log\LogLevel;
class PsrLogAdapter extends \Psr\Log\AbstractLogger
{
private $_levelMap = array(
LogLevel::EMERGENCY => CLogger::LEVEL_ERROR,
LogLevel::ALERT => CLogger::LEVEL_ERROR,
LogLevel::CRITICAL => CLogger::LEVEL_ERROR,
LogLevel::ERROR => CLogger::LEVEL_ERROR,
LogLevel::WARNING => CLogger::LEVEL_WARNING,
LogLevel::NOTICE => CLogger::LEVEL_INFO,
LogLevel::INFO => CLogger::LEVEL_INFO,
LogLevel::DEBUG => CLogger::LEVEL_PROFILE,
);
public $category = 'DEFAULT';
public function init()
{
}
/**
* Logs with an arbitrary level.
*
* @param mixed $level
* @param string $message
* @param array $context
* @return null
*/
public function log($level, $message, array $context = array())
{
if($context) {
$message .= PHP_EOL . PHP_EOL . json_encode($context);
}
Yii::log($message, $this->_levelMap[$level], $this->category);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment