gpt4 book ai didi

cakephp - CakeLog 和范围 : Restricting scope to only one logger

转载 作者:行者123 更新时间:2023-12-02 21:58:36 25 4
gpt4 key购买 nike

我想设置一个日志文件,以便只有 SOAP 范围内的消息才会记录到该文件中。相反,我还想防止在调试和错误的默认日志中记录 SOAP 范围内的消息。

这是我当前在 bootstrap.php 中的设置。

CakeLog::config('soap', array(
'engine' => 'FileLog',
'types' => array('info','debug','error'),
'scopes' => array('soap'),
'file' => 'soap'
));

CakeLog::config('debug', array(
'engine' => 'FileLog',
'types' => array('notice', 'info', 'debug'),
'file' => 'debug',
));
CakeLog::config('error', array(
'engine' => 'FileLog',
'types' => array('warning', 'error', 'critical', 'alert', 'emergency'),
'file' => 'error',
));

这是我的一个库中进行 SOAP 调用的片段。

        CakeLog::debug("REQUEST:\n" . $client->__getLastRequest() . "\n", 'soap');
CakeLog::debug("RESPONSE:\n" . $client->__getLastResponse() . "\n", 'soap');

} catch (SoapFault $e) {
CakeLog::error(print_r($result,true), 'soap');
CakeLog::error('Exception: (' . $e->getCode() . ') ' . $e->getMessage(), 'soap');
if (isset($client)) {
CakeLog::error("Errored REQUEST:\n" . print_r($client->__getLastRequest(), true) . "\n", 'soap');
}

当我进行当前设置时,我在 debug.log 和soap.log 中收到调试soap 消息,这是不可取的。

最佳答案

根据CakeLog::config documentation

If you don't define any scopes an adapter will catch all scopes that match the handled levels.

因此,调试记录器写入类型为 'types' => array('notice', 'info', 'debug'), 的所有消息,

现在如何避免呢?看来你有两种方法:

  • 使用 CakeLog::write 和自定义错误类型

    CakeLog::write('soap', "REQUEST:\n". $client->__getLastRequest() . "\n");

在这种情况下,根据 CakeLog::write method 的文档

integer|string $type Type of message being written. When value is an integer or a string matching the recognized levels, then it will be treated log levels. Otherwise it's treated as scope.

范围和类型将相同并且具有“soap”值,因此,消息不会记录在调试记录器中,而只会记录在soap中。

  • 保留现在的状态,这样可以将所有调试消息保存在一个文件中,并将某些消息保存在某些特定日志中,这并不是一个坏主意。

关于cakephp - CakeLog 和范围 : Restricting scope to only one logger,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17331705/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com