【问题标题】:pattern not matched fluentd elasticsearch模式不匹配流利的弹性搜索
【发布时间】:2016-04-30 07:48:06
【问题描述】:

我一直坚持在 fluentd 中为 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} [] []

谢谢

【问题讨论】:

  • 你想要输出什么?
  • 我不知道fluentd但是check
  • 如果还有问题,请在问题中添加您的fluentd配置。

标签: regex elasticsearch fluentd


【解决方案1】:

您正在使用字符类[] 和不必要的$。我修改了一些你的正则表达式,它可以工作

(?<Time>[^ ]* [^ ]*)\ (?<Level>[^ ]*): (?<Exception>[^\n]+)\n*(?<StackTrace>Stack trace:)

Regex Demo

这个正则表达式也可以帮助你

(\[[^]]+\])\s+([^:]+):\s+([^\n]+)\n*(Stack trace:)\n

Regex Demo

【讨论】:

  • @BilalUsean 请注意,我修改的正则表达式在失败的情况下效率很低
猜你喜欢
  • 2015-03-12
  • 1970-01-01
  • 2020-05-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多