kuvalda-amqp/AmqpLoger.php

38 lines
1.0 KiB
PHP
Raw Permalink Normal View History

2024-11-20 12:51:47 +03:00
<?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)
);
}
}