【问题标题】:Regex for Heka to read Monolog logfileHeka 读取 Monolog 日志文件的正则表达式
【发布时间】:2014-05-02 22:46:33
【问题描述】:

我试图让 Heka 读取我的 Monolog 文件(以便我可以使用 Kibana 查看它们),但它一直告诉我没有匹配项。

这是我的 Heka 配置中的 match_regex

match_regex = "^\\[(?P<Timestamp>.*)\\] (?P<Channel>.+?)\\.(?P<Severity>[A-Z]+): (?P<Message>.*)"

这是日志中的示例行

[2014-03-24 19:07:08] event.DEBUG: Notified event "kernel.terminate" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelTerminate"

根据 regex101 (see here),正则表达式非常好。然而海拉却告诉我不匹配。

有人能指点我正确的方向吗,我昨天花了一整天的时间试图让它发挥作用。

编辑:我能找到的关于 Heka 和 Monolog 的唯一文档是这些幻灯片 here

编辑:我刚刚发现了这个:https://regoio.herokuapp.com/

这告诉我它应该使用以下内容:

match_regex = '^\[(?P<Timestamp>.*)\] (?P<Channel>.+?)\.(?P<Severity>[A-Z]+): (?P<Message>.*)'

但事实并非如此。

【问题讨论】:

  • 可能是因为正则表达式以^ 开头?也许您需要设置正则表达式多行修饰符之类的?这使得 ^ 也匹配行的开头,而不仅仅是完整字符串的开头。 regular-expressions.info/anchors.html
  • 似乎 ^ 不是问题,似乎我缺乏注意力是问题,我确实尝试过使用和不使用 ^ 但没有得到任何东西,只是因为我忘记设置输出

标签: regex kibana monolog


【解决方案1】:

很明显我昨天没有醒,在确定正则表达式正确 15 次后,我意识到我忘记了

[LogOutput]
 message_matcher = "TRUE"

[ElasticSearchOutput]
 message_matcher = "TRUE"

在我的hekad.toml 文件中

我的完整文件现在看起来像这样:

[pos_log]
type = "LogfileInput"
logfile = "/home/sam/git/PosBranch/app/logs/dev.log"
decoder = "monolog_decoder"

[monolog_decoder]
type = "PayloadRegexDecoder"
match_regex = '^\[(?P<Timestamp>.*)\] (?P<Channel>.+?)\.(?P<Severity>[A-Z]+): (?P<Message>.*)'
timestamp_layout = "2006-01-02 15:04:05"
timestamp_location = "UTC" # optional, default value

[monolog_decoder.severity_map]
DEBUG = 7
INFO = 6
NOTICE = 5
WARNING = 4
ERROR = 3
CRITICAL = 2
ALERT = 1
EMERGENCY = 0

[monolog_decoder.message_fields]
Type = "monolog_log"
Logger = "sam"
Hostname = "local"
Channel = "%Channel%"
Message = "%Message%"
Payload = ""

[LogOutput]
 message_matcher = "TRUE"

[ElasticSearchOutput]
 message_matcher = "TRUE"

消息现在正在滚动到 kibana :)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-07
    相关资源
    最近更新 更多