How to Configure Grails application for sending your application logs to Loggly using log4j SyslogAppender.

Posted By : Sanjay Saini | 27-Sep-2014

Hi Friends,

In this blog ,I am going to explain you how to Send your application logs to Loogly using Log4j syslog appender. The SyslogAppender will send them to your existing syslog daemon, which will then send them to Loggly. We automatically parse out several log4j fields.

Following Steps must be followed for sending application Logs to loggly.

Step 1 : Configure Rsyslog .

If you haven't already, please follow instruction defined in previous blog for Configure Rsyslog in Linux for sending Linux Systems Logs to Loggly.

http://www.oodlestechnologies.com/blogs/How-to-Configure-Rsyslog-in-Linux--for-sending-Linux-Systems-Logs-to-Loggly

please follow the above link instructions to configure Rsyslog in linux .

Step 2 : Open rsyslog.conf file in vim editor command for open :

sudo vim  /etc/rsyslog.conf

Enable UDP input by uncommenting these lines from rsyslog.conf file

 
$ModLoad imudp
$UDPServerRun 514

save changes and restart rsyslog.

Step 3 : Edit Config.groovy file for Configure Log4j in grails Application.

 Path of config file---->applicationName/grails-app/conf/config.groovy 

 Dowanload org.apache.log4j.net jar and add on your build path.

 import it in config.groovy file.

 import org.apache.log4j.net.SyslogAppender

Copy and paste below code inside

log4j{
      appenders{         
                 appender new SyslogAppender(
                                             name: 'syslog',
                                             facility: 'LOCAL3',
                                             syslogHost: 'localhost',
                                             header:true,
                                             layout: pattern(conversionPattern: 'java %d{dd-MM-yyyy HH:mm:ss,SSS} %5p %c{2} - %m%n')
                                             )
                     root{                                                    
                           debug 'syslog'
                          }

                                 
              }
   }
			
Step 4 : Restart your application for changes take effect.
Step 5 : Verify the logs on Loggly. For verifying logs on Loggly.
Open your loogly account and Type "logtype:java" on search box and search logs received in last 10 minutes.
 
Hope it is useful for you :)
Thank you 
Sanjay Saini

 

About Author

Author Image
Sanjay Saini

Sanjay has been working on web application development using frameworks like Java, groovy and grails. He loves listening to music , playing games and going out with friends in free time.

Request for Proposal

Name is required

Comment is required

Sending message..