38 lines
1.0 KiB
PHP
38 lines
1.0 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace dominion\amqp;
|
||
|
|
||
|
use Yii;
|
||
|
use yii\log\FileTarget;
|
||
|
|
||
|
class AmqpLoger extends FileTarget
|
||
|
{
|
||
|
|
||
|
public static function log($type, $result, $prefixFile = '')
|
||
|
{
|
||
|
$model = new AmqpLoger;
|
||
|
if (isset(Yii::$app->params['log']['maxFileSize']) && Yii::$app->params['log']['maxFileSize'] > 1)
|
||
|
{
|
||
|
$model->maxFileSize = Yii::$app->params['log']['maxFileSize'];
|
||
|
}
|
||
|
if (isset(Yii::$app->params['log']['maxLogFiles']) && Yii::$app->params['log']['maxLogFiles'] > 1)
|
||
|
{
|
||
|
$model->maxLogFiles = Yii::$app->params['log']['maxLogFiles'];
|
||
|
}
|
||
|
$model->logFile = Yii::getAlias(Yii::$app->params['log']['dir']) . $prefixFile . (empty($prefixFile) ? $type : ucfirst($type) ) . '.log';
|
||
|
$model->messages = [$result];
|
||
|
$model->export();
|
||
|
}
|
||
|
|
||
|
public function formatMessage($result)
|
||
|
{
|
||
|
return sprintf(
|
||
|
"[%s]\t%s\t%s",
|
||
|
date(\DateTime::ISO8601),
|
||
|
getmypid(),
|
||
|
json_encode($result, JSON_UNESCAPED_UNICODE)
|
||
|
);
|
||
|
}
|
||
|
|
||
|
}
|