3

我有一个自定义格式的日志文件,日期字段如下所示:

Dec  4 23:59:21
Nov 21 23:59:21

在我的 logstash 配置中,我有这个过滤器:

date {
    type => "custom"
    # tell it the format
    custom_timestamp => ["MMM  d HH:mm:ss", "MMM dd HH:mm:ss"]
    # locale didn't help
    locale => "en"
}
mutate{
    type => "custom"
    # replace the timestamp
    replace => ["@timestamp", "%{custom_timestamp}"]
}

据说它用日志中的自定义时间戳替换了logstash时间戳(我目前正在从旧日志中回填它以进行测试)。

如果我打开调试标志并输出到标准输出,它会显示@timestamp已被替换,custom_timestamp但我收到一条错误消息,告诉我它无法导入:

:exception=>java.lang.IllegalArgumentException: Invalid format: "Dec  4 23:59:21"

我该怎么做才能转换日期格式?

4

2 回答 2

1

Turns out that the sample I was working from is wrong. You do not need the mutate replacement, the config is this now:

date {
    type => "custom"
    # tell it the format
    custom_timestamp => ["MMM  d HH:mm:ss", "MMM dd HH:mm:ss"]
    # date format is english, computer might not be
    locale => "en"
}
mutate{
    type => "custom"
    #other mutations go here
}
于 2012-12-06T15:27:30.717 回答
0

这篇文章有两个误解:

  1. 生成 java 异常是因为您的格式中没有 YEAR,因此它无法安全地解析日期。
  2. 如果您希望其他应用程序将您的旧导入日志视为连贯的时间线,则需要运行 mutate。否则,当您导入所有旧日志时,您只会看到几分钟的事件集中(在导入期间)。

除此之外,很好的问题/答案,它帮助我回到了我的特定问题上;)

于 2013-09-17T13:16:41.553 回答