日志无法在yii2中工作
我想在app.log,我的配置文件中放一个日志日志无法在yii2中工作,yii2,Yii2,我想在app.log,我的配置文件中放一个日志 'log' => [ 'traceLevel' => YII_DEBUG ? 3 : 0, 'targets' => [ 'file' => [ 'class' => 'yii\log\FileTarget', 'levels' => ['error', 'warning'],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
'file' => [
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
'logFile' => '@root/console/runtime/logs/app.log',
],
]
]
控制器动作中
public function actionRankCalculation()
{
$allConest = Contest::find()->where('isActive = 1')->all();
Yii::trace('start calculating average revenue');
$response = [];
/** @var Contest $contest */
foreach ($allConest as $contest) {
$videoQuery = Video::find()->where('contest_id = ' . $contest->id);
$videoQuery->andWhere('isActive = 1');
$videoQuery->orderBy([
'global_likes' => SORT_DESC,
'id' => SORT_ASC,
]);
public function actionIndex(){
Yii::error('Test index action', $category = 'test1'); }
}
但是Yii::trace(‘开始计算平均收入’);不工作您可以尝试此操作。请使用类别。例如,如下所示
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error'],
'categories' => ['test1'],
'logFile' => '@app/Test/test1.log',
],
并在控制器动作中使用下面的一个
public function actionRankCalculation()
{
$allConest = Contest::find()->where('isActive = 1')->all();
Yii::trace('start calculating average revenue');
$response = [];
/** @var Contest $contest */
foreach ($allConest as $contest) {
$videoQuery = Video::find()->where('contest_id = ' . $contest->id);
$videoQuery->andWhere('isActive = 1');
$videoQuery->orderBy([
'global_likes' => SORT_DESC,
'id' => SORT_ASC,
]);
public function actionIndex(){
Yii::error('Test index action', $category = 'test1'); }
您可以试试这个。使用类别。例如,如下所示
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error'],
'categories' => ['test1'],
'logFile' => '@app/Test/test1.log',
],
并在控制器动作中使用下面的一个
public function actionRankCalculation()
{
$allConest = Contest::find()->where('isActive = 1')->all();
Yii::trace('start calculating average revenue');
$response = [];
/** @var Contest $contest */
foreach ($allConest as $contest) {
$videoQuery = Video::find()->where('contest_id = ' . $contest->id);
$videoQuery->andWhere('isActive = 1');
$videoQuery->orderBy([
'global_likes' => SORT_DESC,
'id' => SORT_ASC,
]);
public function actionIndex(){
Yii::error('Test index action', $category = 'test1'); }
尝试在控制台配置中将
flushInterval
和exportInterval
设置为1:
return [
'bootstrap' => ['log'],
'components' => [
'log' => [
'targets' => [
[
'class' => 'yii\log\FileTarget',
'exportInterval' => 1,
],
],
'flushInterval' => 1,
],
],
];
它使每个日志消息立即出现在日志中。尝试在控制台配置中将
flushInterval
和exportInterval
设置为1:
return [
'bootstrap' => ['log'],
'components' => [
'log' => [
'targets' => [
[
'class' => 'yii\log\FileTarget',
'exportInterval' => 1,
],
],
'flushInterval' => 1,
],
],
];
它使每个日志消息立即出现在日志中。如果您的正确,请尝试
Yii::error('start computing average revenue')
它将生成日志文件或添加``。或添加'levels'=>['error'、'warning'、'trace'],
如果您的操作正确,请尝试Yii::error('start computing average revenue')代码>它将生成日志文件或添加``。或添加'levels'=>['error','warning','trace'],