我坚持用流利的magento异常日志写日志格式。
exception.log
的单一例外[2016-04-30 11:37:42] main.CRITICAL: exception 'Exception' with message 'Report ID: webapi-571f53065307a; Message: Notice: Array to string conversion in /var/www/html/magento2/vendor/monolog/monolog/src/Monolog/Logger.php on line 277' in /var/www/html/magento2/vendor/magento/framework/Webapi/ErrorProcessor.php:194
Stack trace:
#0 /var/www/html/magento2/vendor/magento/framework/Webapi/ErrorProcessor.php(139): Magento\Framework\Webapi\ErrorProcessor->_critical(Object(Exception))
#1 /var/www/html/magento2/vendor/magento/module-webapi/Controller/Rest.php(163): Magento\Framework\Webapi\ErrorProcessor->maskException(Object(Exception))
#2 /var/www/html/magento2/var/generation/Magento/Webapi/Controller/Rest/Interceptor.php(24): Magento\Webapi\Controller\Rest->dispatch(Object(Magento\Framework\App\Request\Http))
#3 /var/www/html/magento2/vendor/magento/framework/App/Http.php(115): Magento\Webapi\Controller\Rest\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
#4 /var/www/html/magento2/vendor/magento/framework/App/Bootstrap.php(258): Magento\Framework\App\Http->launch()
#5 /var/www/html/magento2/index.php(39): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http))
#6 {main} [] []
注意:那里共有9行(但总行数因异常而异)
异常日志格式的正则表达式模式是
/^\[(?<Time>[^ ]* [^ ]*)\] (?<Level>[^ ]*): (?<Exception>.*\n.*):(?<StackTrace>.*\n)$/
但它不起作用,什么是正确的模式也收集异常日志。
注意:我已与http://fluentular.herokuapp.com/核对,但未发现任何错误。
我希望输出应该如下所示
Time:[2016-04-30 11:37:42]
Level:main.CRITICAL
Exception:exception 'Exception' with message 'Report ID: webapi-571f53065307a; Message: Notice: Array to string conversion in /var/www/html/magento2/vendor/monolog/monolog/src/Monolog/Logger.php on line 277' in /var/www/html/magento2/vendor/magento/framework/Webapi/ErrorProcessor.php:194
StackTrace:#0 /var/www/html/magento2/vendor/magento/framework/Webapi/ErrorProcessor.php(139): Magento\Framework\Webapi\ErrorProcessor->_critical(Object(Exception))
#1 /var/www/html/magento2/vendor/magento/module-webapi/Controller/Rest.php(163): Magento\Framework\Webapi\ErrorProcessor->maskException(Object(Exception))
#2 /var/www/html/magento2/var/generation/Magento/Webapi/Controller/Rest/Interceptor.php(24): Magento\Webapi\Controller\Rest->dispatch(Object(Magento\Framework\App\Request\Http))
#3 /var/www/html/magento2/vendor/magento/framework/App/Http.php(115): Magento\Webapi\Controller\Rest\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
#4 /var/www/html/magento2/vendor/magento/framework/App/Bootstrap.php(258): Magento\Framework\App\Http->launch()
#5 /var/www/html/magento2/index.php(39): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http))
#6 {main} [] []
由于
答案 0 :(得分:0)
您正在使用字符类[]
和不必要的$
。我修改了一些你的正则表达式,它的工作原理
(?<Time>[^ ]* [^ ]*)\ (?<Level>[^ ]*): (?<Exception>[^\n]+)\n*(?<StackTrace>Stack trace:)
<强> Regex Demo 强>
这个正则表达式也可以帮助你
(\[[^]]+\])\s+([^:]+):\s+([^\n]+)\n*(Stack trace:)\n
<强> Regex Demo 强>