I found a solution to my problem.
I created a custom log level for my class for which I want separate logs.
I tried the following log4j configuration:
log4j.rootCategory=DEBUG, LOGFILE_ENGINE
log4j.category.packageName.className = DEBUG, packageName.className.syncLogger
log4j.additivity.packageName.className= false
log4j.appender.LOGFILE_ENGINE=org.apache.log4j.RollingFileAppender
log4j.appender.LOGFILE_ENGINE.File=${catalina.home}/logs/file1.log
.....................
log4j.appender.packageName.className.syncLogger=org.apache.log4j.RollingFileAppender
log4j.appender.packageName.className.syncLogger.File=${catalina.home}/logs/file2.log
log4j.appender.packageName.className.syncLogger.Threshold=DISASTER#packageName.SyncLogLevel
.....................
And, I created the logger reference as follows:
private static final String FQCN = className.class.getName();
private static final String SYNC_LOGGER_NAME = FQCN + ".syncLogger";
public static customLoggingClassName syncLogger = Logger.getLogger(SYNC_LOGGER_NAME);
Below is the Custom Level Class(SyncLogLevel) for creating a custom Level (DISASTER):
public class SyncLogLevel extends Level{
private static final long serialVersionUID = 1L;
public SyncLogLevel(int level, String levelStr, int syslogEquivalent) {
super(level, levelStr, syslogEquivalent);
}
public static SyncLogLevel toLevel(int val, Level defaultLevel) {
return DISASTER;
}
public static SyncLogLevel toLevel(String sArg, Level defaultLevel) {
return DISASTER;
}
public static final SyncLogLevel DISASTER = new SyncLogLevel(60000, "DISASTER", 0);
}
After this you have to do your logging in the desired class as follows:
syncLogger.log(SyncLogLevel.DISASTER, "Log Message");
At the end all the log messages called from syncLogger with the log level "DISASTER" will go to a separate file(file2.log)
After doing all this, All my logs go into desired files separately.