Graylog Integration with Logback


Objective: 

To demonstrate the steps to integrate graylog with logback logging implementation

Prerequisites:

1. An exciting application with logback enables logging
2. JDK1.5(Specific fix)/JDK 1.6+
3. GELF dependency for Logback

 Name Logback dependency Compatible JDK Status
 logback-gelf <dependency>
<groupId>me.moocar</groupId>
<artifactId>logback-gelf</artifactId>
<version>0.9.6p2</version>
</dependency>
 JDK1.6/+ Worked

 

Step-1

logback-gelf dependency is built on JDK1.6/+ and using some additional functions(copyOfRange() and copyOf()).

Add mentioned dependency into pom.xml(Web and enterprise package)

 

Step-2

Appender for Graylog

You need to add following appender to integrate graylog in logback configuration.

For the respective values, please visit grayling user guide.

Property Name  Used for  
Value
 useLoggerName  To log the logger name  true
 useThreadName  To log the thread name  true

For more details on properties, please click here

Step-3

Root Loger and default appender

To feed the log into graylog server, set default root logger level and appender in logback.xml.

Default Root Logger

 

Step-4

TCP supported Appender problem

Normal GELF appender uses TCP protocol and that makes synchronous call. Because of this behaviour, there will be minor/major performance impact on the application. Resultant of this, the response time will increased.

So, to overcome from this problem(Step-5), feed the log to graylog server asynchronously. So that there won’t be any impact on application performance.

 

Step-5

Integrate ASYNC appender

Add below appender into logback.xml and set this as default appender for root logger.

ASYNC Appender Default Root Logger
 <appender name=”ASYNC” class=”ch.qos.logback.classic.AsyncAppender”><param name=”queueSize” value=”500″/>
<appender-ref ref=”GELF” />
</appender>
 <root level=”INFO”><appender-ref ref=”ASYNC” />
</root>
Property Meaning
queueSize This is used to buffer the no of message events to log into graylog server. The default value for this is 256.

 

Step-6

To disable the graylog Solution
<root level=”INFO”>
<!–<appender-ref ref=”ASYNC” />–>
</root>
1. Commen out the ASYNC Appender ref from root logger.
2. Remove this entry itself from root logger.

 

Step-7

Below is pop up screen to search any log. Search is enable for any of the below parameter, to search based on application then enter facility/application name in highlighted area and hit “Run filter”.

image post 3

To search based on log message, search using Full message with ‘*’ as prefix. e.g. *PROVIDER_REQUEST

share or like this post
Share

One thought on “Graylog Integration with Logback

  1. FranHancockq

    I see your website needs some unique articles. Writing manually is time consuming,
    but there is solution for this hard task. Just search for – Miftolo’s tools rewriter

Leave a Reply

Your email address will not be published. Required fields are marked *

Share