【问题标题】:logstash output to file and ignores codeclogstash 输出到文件并忽略编解码器
【发布时间】:2015-06-29 05:52:17
【问题描述】:

请有人向我解释一下,为什么logstash一直忽略“编解码器=>普通=>格式”设置,我正在尝试设置?

我正在使用的 Cfg 文件:

 input {
        gelf {
                host => "[some ip]"
                port => 12201
        }
}

output {
        elasticsearch {
                host => "[some ip]"
                bind_port => "9301"
        }

        file {
                codec => plain {
                        format => "%{[time]} | %{[severity]} : /%{[thread]}/ %{[loggername]} (%{[sourcemethodname]}) - %{[message]}"
                }
                path => "/Users/[some user]/logs/%{host}/%{facility}-%{+YYYY-MM-dd}.log"
        }
}

我以为我使用了错误的格式,为字段尝试了不同的组合,例如“%{time}”,甚至尝试使用常量文本,例如:

codec => plain {format => "Simple line"}

但似乎没有任何效果。它很好地输出到 elasticsearch,创建文件夹/文件,但将其输出为 JSON。

如果有人知道这是怎么回事,请帮忙。 谢谢。

【问题讨论】:

    标签: file output logstash


    【解决方案1】:

    参数 message_format 已弃用,并将在 Logstash 的未来版本中删除。而不是使用message_format 尝试这样的事情:

    file {
      codec => line {
        format => "%{[time]} | %{[severity]} : /%{[thread]}/ %{[loggername]} (%{[sourcemethodname]}) - %{[message]}"
      }
      path => "/Users/[some user]/logs/%{host}/%{facility}-%{+YYYY-MM-dd}.log"
    }
    

    PS:您的示例使用编解码器plain,请尝试使用line

    【讨论】:

      【解决方案2】:

      file 有一个 message_format 参数,这是您想要使用的:

      file {
        message_format => "%{[time]} | %{[severity]} : /%{[thread]}/ %{[loggername]} (%{[sourcemethodname]}) - %{[message]}"
        path => "/Users/[some user]/logs/%{host}/%{facility}-%{+YYYY-MM-dd}.log"
      }
      

      【讨论】:

      • 非常感谢!这正是我所需要的。希望从 Logstash 文档中更清楚。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-22
      • 1970-01-01
      • 2014-08-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多