我坚持写流利的magento异常日志的日志格式。
exception.log 的单个异常(exception)
[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} [] []
谢谢
最佳答案
您正在使用字符类[]
和不必要的$
。我修改了您的正则表达式,它可以正常工作
(?<Time>[^ ]* [^ ]*)\ (?<Level>[^ ]*): (?<Exception>[^\n]+)\n*(?<StackTrace>Stack trace:)
Regex Demo
此正则表达式还可以帮助您
(\[[^]]+\])\s+([^:]+):\s+([^\n]+)\n*(Stack trace:)\n
Regex Demo
关于regex - 模式不匹配流利 Elasticsearch ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36952294/