I am using log4j 2 along with json pattern layout to create the logs and using the logstash agent 1.4.2 to port the logs in to a redis. In my logs i am trying to log some json payloads which includes some nested json. Also i am using json filter to parse the json. My issue is when parsing the json into fields is not happening properly.
My issues are
- flat json is not parsed unless two json filters added
- nested jsons will not be parsed and even 2 json filters are appears
below are my configurations
- logstash shipper.conf
input {
file {
tags => ["messaging-stg"]
path => "/opt/messaging/logs/logs.log"
debug => true
type => "messaging-stg"
}
}
filter {
if [type]== "messaging-stg" {
json {
source => "message"
}
# first filter parse entire json message to a "field" called "message" from "_source"
json {
source => "message"
}
# second filter parse flat json message to fields
}
}
output {
redis {
host => [
"server_01" ,
"server_02"
]
shuffle_hosts => true
data_type => "list"
key => "logstash"
}
}
- log4j2.xml
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="info">
<properties>
<property name="pattern">%m%n</property>
<property name="filePath">/opt/messaging/logs</property>
<property name="fileName">logs</property>
</properties>
<Appenders>
<RollingFile name="RollingFile" fileName="${filePath}/${fileName}.log"
filePattern="${filePath}/${fileName}-%d{yyyy-MM-dd}-%i.log" append="true">
<JSONLayout complete="false" compact="true" eventEol="true" charset="UTF-8" />
<PatternLayout>
<pattern>${pattern}</pattern>
</PatternLayout>
<Policies>
<SizeBasedTriggeringPolicy size="10 KB"/>
</Policies>l
</RollingFile>
<Console name="STDOUT" target="SYSTEM_OUT">
<PatternLayout>
<pattern>${pattern}</pattern>
</PatternLayout>
</Console>
</Appenders>
<Loggers>
<Root level="debug">
<AppenderRef ref="RollingFile"/>
<AppenderRef ref="STDOUT"/>
</Root>
</Loggers>
</Configuration>
check for following sample json
-
success full flat json parsing
{
"Msgtype": "SentToxxxxxxxx",
"ActionType": "xxxxxx",
"userstd": {
"user": {
"userproperty": {
"lastupdate": "",
"createdate": "",
"propertyvalue": "",
"propertyname": ""
},
"clientid": 444444,
"lastupdate": "2016-08-25T03:30:09.067",
"emailaddress": "xxxxxx@xxxxxx.com",
"userid": 4444444,
"createdate": "2016-08-25T03:30:09.067",
"action": "xxxxxxx",
"lastname": "xxxxxxx",
"loginid": "xxxxx",
"firstname": "xxxxx",
"password": "xxxxxxxx"
},
"version": ""
}
} -
unsuccessfull nested json parsing
{
"Msgtype": "Receivedfromxxxxx",
"ActionType": "xxxxxx",
"userstd": {
"user": {
"clientid": 4444444,
"lastupdate": "",
"emailaddress": "",
"createdate": "",
"userid": 4444444,
"lastname": "",
"enrollment": {
"lastupdate": "",
"enrolltype": "course",
"roleid": 1,
"createdate": "2016-08-24T22:37:55.555",
"clientnodeid": 4444444,
"comment": ""
},
"firstname": "",
"loginid": "",
"password": ""
},
"version": ""
}
}