2016-07-01 64 views
0

我有一个文件mylog.log其中有以下内容。如何为log4j消息配置logstash过滤器?

2014-07-02 20:52:39 DEBUG HelloExample:19 - This is debug : ishan 
2014-07-02 20:52:39 INFO HelloExample:23 - This is info : ishan 
2014-07-02 20:52:39 WARN HelloExample:26 - This is warn : ishan 
2014-07-02 20:52:39 ERROR HelloExample:27 - This is error : ishan 
2014-07-02 20:52:39 FATAL HelloExample:28 - This is fatal : ishan 

我有logstash以下的conf文件

input { 
    file { 
    path => "/home/ishan/sf_shared/log4jlogs/1-7-2016.txt" 
    start_position => "beginning" 
    codec => multiline { 
     pattern => "(^d+serror)|(^.+Exception: .+)|(^s+at .+)|(^s+... d+ more)|(^s*Caused by:.+)" 
     what => "previous" 
    } 
    } 
} 
output { 
    elasticsearch => ["127.0.0.1:9200"] 
    stdout { codec => rubydebug } 
} 

所以,当我运行logstash用下面的命令 的/ opt/logstash /斌/ logstash -f log4j.conf

但它不会在控制台上显示任何内容。 那么,如何在控制台上显示它?还添加了它之后如何检查ES?需要什么样的过滤器来解析以下json格式的信息?

{ 
    "severity": DEBUG 
    "class": HelloExample 
    "message":This is debug : ishan 
} 

在此先感谢。

+0

你可以使用grok你的模式。你的多行看起来没有必要,因为你已经只有1行日志?另外,^ d不会注释日期。研究grok的正确模式 – pandaadb

回答

0

你需要看看grok模式。检查这link。 这应该适合你:

input { 
    file { 
    path => "/home/ishan/sf_shared/log4jlogs/1-7-2016.txt" 
    start_position => "beginning" 
    } 
} 
filter { 
    grok { 
     match => { 
      "message" => '%{YEAR}[-]%{MONTHNUM}[-]%{MONTHDAY} %{TIME} %{LOGLEVEL:severity} %{GREEDYDATA:class}%{INT} - %{GREEDYDATA:mess}' 
     } 
    } 
} 
output { 
    elasticsearch => ["127.0.0.1:9200"] 
    stdout { codec => rubydebug } 
} 
+0

我试图用此启动logstash并得到以下错误 grok {:level =>:error}的未知设置'log' –

+0

@IshanBhatt现在检查。 – PuRaK

+0

grok {:level =>:error}的未知设置'message' –