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 manage more than one log files.
Two simple steps to define multiple log files according to log level priority:
1. In appender block of log4j block in Config.groovy, add the appenders according to the number of log files. Here I have created two different log files, first one is for debug level logs and second one is for error level logs.
* In appenders block, generated log file name will be with file attribute,
* and log level will define with threshold.
rollingFile name:’debugLog’, file:’debug.log’, threshold: org.apache.log4j.Level.DEBUG
rollingFile name:’errorLog’, file:’error.log’, threshold: org.apache.log4j.Level.ERROR
2. declare all the appenders in root block of log4j block in Config.groovy file as:
info ‘debugLog’, ‘errorLog’
Thats it. 🙂
Note: When we are using log level files, then log level file will contain all that log level messages of that priority level and priority level above that.