Java, Technology

Structured logging in logback using MDC

General Use Case When any application fails in production then it is necessary is to track how the execution went. For this the standard approach is to add logs. Logs can be helpful in tracking how the execution went but tracking the execution becomes more difficult in multithreaded applications. The logs start to get jumbled for...

by Aseem Bansal
Tag: log4j
24-Nov-2015

Grails, Technology

Externalize and reload grails Log4j configuration

In Grails 2.x and in some earlier versions, the log4j configuration resides in grails-app/conf/Config.groovy. We can modify log4j closure here to add new categories and tweak the log levels. In development environemnt any changes to log4j closure are loaded automatically without bouncing the application, but not when the application is...

by Sandeep Poonia
Tag: log4j
01-Jul-2015

Technology

@Log annotation

@Log : This annotation provides the log object in groovy class. By using it you don't need to create the Logger object, it automatically provides log object. Example: [groovy] import groovy.util.logging.Log @Log class Person { String name String address String city public void logDetails(){ ...

by Mohit Garg
Tag: log4j
26-Sep-2012

Grails

Log4j: Creating Different Log Files Every Day

To avoid getting log messages in single log file we can create a new log file every day in just one step. This can be done very easily by using DailyRollingFileAppender instead of RollingFileAppender . We just need to add a new Log4J appenders to our configuration file (Config.groovy). In the following example we create a...

by Gunpreet
Tag: log4j
05-Sep-2012

Grails

Manage Multiple Log File

Different Levels of Logging to Different Appenders or Files: When a project is running, then lot of log messages (all type of log messages e.g. Error, Fatal, Warning, Info, Debug etc.) are logged into a single log file. Many times we try to find the error messages only, instead of debugging the complete application. In that case we...

by Amit Kumar
Tag: log4j
24-Aug-2012

Grails

Send Mail via Log4j with SMTP Appender

Grails supports sending all log messages(error,fatal etc.) to a support team or to yourself, by email (gmail account), via log4j with SMTP Appender. 1. For this we have to do some configration in Config.groovy as shown below: [groovy] // import SMTPAppender and Log4j Lever classes import org.apache.log4j.net.SMTPAppender import...

by Amit Kumar
Tag: log4j
13-Aug-2012

Grails

Using Groovy MOP and Closure to prevent expression evaluation in logger.debug()

Generally in our code, we have lots of debug statements that prints the intricate details of the state of the program. Infact, the debug statements are meant for doing this. Sometimes, these debug statements may contain a call to some other method to evaluate what is to be logged. [java] //Logging statement calling some function to...

by Mohd Farid
Tag: log4j
13-Dec-2010