log4j logs

Last Updated: Jun 15, 2017

Log collection methods

Log Service supports collection of log4j logs in two ways:

  • By using LogHub log4j Appender
  • By using Logtail to collect log4j log files

LogHub log4j Appender

For detailed introductions and operations, refer to log4j appender.

Log collection by Logtail

The following shows the sample log of log4j default format printed to a file.

  1. 2013-12-25 19:57:06,954 [10.207.37.161] WARN impl.PermanentTairDaoImpl - Fail to Read Permanent Tair,key:e:470217319319741_1,result:com.example.tair.Result@172e3ebc[rc=code=-1, msg=connection error or timeout,value=,flag=0]

Matching of the beginning of a line in multiline logs (the beginning of a line is expressed by IP information):

  1. \d+-\d+-\d+\s.*

Regular expression used to extract log information:

  1. (\d+-\d+-\d+\s\d+:\d+:\d+,\d+)\s\[([^\]]*)\]\s(\S+)\s+(\S+)\s-\s(.*)

Time conversion format:

  1. %Y-%m-%d %H:%M:%S

Sample log extraction result:

Key Value
time 2013-12-25 19:57:06,954
ip 10.207.37.161
level WARN
class impl.PermanentTairDaoImpl
message Fail to Read Permanent Tair,key:e:470217319319741_1,result:com.example.tair.Result@172e3ebc[rc=code=-1, msg=connection error or timeout,value=,flag=0]
Thank you! We've received your feedback.