Yii2始终使用$ _COOKIE,$ _SESSION和$ _SERVER(类别过滤器无法正常工作)记录应用程序类别

时间:2015-09-16 07:51:14

标签: php logging yii2

我是Yii2的新用户,在发生某些操作后,我需要手动记录到数据库。对我来说最好的事情是按类别过滤。问题是Yii2总是添加额外的信息$ _COOKIE,$ _SESSION和$ _SERVER。 这是正常的吗?如何禁用额外的日志行?

这是前端配置

return [
    'id' => 'app-frontend',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['log'],
    'controllerNamespace' => 'frontend\controllers',
    'components' => [
        'user' => [
            'identityClass' => 'common\models\User',
            'enableAutoLogin' => true,
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\DbTarget',
                    'categories' => ['manual'],
                ]
            ],
        ],
        'errorHandler' => [
            'errorAction' => 'site/error',
        ],
    ],
    'params' => $params,
];

这是行动代码:

public function actionTest()
{
    $logger = Yii::getLogger();
    \Yii::info('catalog info', 'manual');
    $logger->flush();
    Yii::$app->end();
}

这就是结果:

enter image description here

感谢 rkm 回答,此配置现在有效:

[
    'id' => 'app-frontend',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['log'],
    'controllerNamespace' => 'frontend\controllers',
    'components' => [
        'user' => [
            'identityClass' => 'common\models\User',
            'enableAutoLogin' => true,
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'except' => [
                        'manual',
                    ],
                    'class' => 'yii\log\FileTarget',
                    'categories' => ['application'],
                ],
                [
                    'class' => 'yii\log\DbTarget',
                    'categories' => ['manual'],
                    'logVars' => [],
                ]

            ],
        ],
        'errorHandler' => [
            'errorAction' => 'site/error',
        ],
    ],
    'params' => $params,
];

1 个答案:

答案 0 :(得分:9)

如果您不需要任何全局变量,请将配置中的'logVars' => [],添加到log组件中。

'components' => [
    ...
    'log' => [
        ...  
        'targets' => [
            [
                'class' => 'yii\log\FileTarget',
                'logVars' => [],
            ]
        ]
        ...
    ]
...
]

有关配置记录in the docs

的详细信息