Last active
August 29, 2015 14:05
-
-
Save sokil/56654a5abdfbcce411ea to your computer and use it in GitHub Desktop.
Yii-PSR Log Adapter
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 | |
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