log4j properties
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Madhuri_Bele
Posted On:   Saturday, December 4, 2004 12:29 AM

Hi,
Can someone help me in writing a log4j.properties file. I have to redirect to 2 files based on the level of logging. Suppose, for the INFO logging level, i have to redirect to info.log and for DEBUG logging level, i have to redirect to debug.log. Please help me.
-Madhuri

Re: log4j properties

Posted By:   Anonymous  
Posted On:   Tuesday, December 21, 2004 10:12 PM

Log4j Properties:

log4j.rootCategory=DEBUG

######### Application Log properties for Learning Synergy #########

log4j.logpath=c://devtools//jboss-3.2.5//server//default//deploy//LS3.war//logs

log4j.category.ls3=DEBUG,S1

log4j.appender.S1=org.apache.log4j.RollingFileAppender

log4j.appender.S1.File=ls3.log

log4j.appender.S1.MaxFileSize=2MB

log4j.appender.S1.MaxBackupIndex=10

log4j.appender.S1.append=true

log4j.appender.S1.layout=org.apache.log4j.PatternLayout

log4j.appender.S1.layout.ConversionPattern=Date=%d{MMM dd yyyy} at Time=%d{HH:mm:ss} %-5p : %m %n



------------------------------------

Method to return Custom Logger

-------------------------------------

private static Category getInstance(String aConfigFile) {

java.util.Properties lProperties = new java.util.Properties();

java.io.InputStream lInputStream= null;

File lFolderPath;

try {

lInputStream = LogManager.class.getClassLoader().getResourceAsStream("log4j.properties");

lProperties.load(lInputStream);

if(!(new File(lProperties.getProperty("log4j.logpath")).exists()))

{

lFolderPath=new File(lProperties.getProperty("log4j.logpath"));

lFolderPath.mkdirs();

}

else

{

lFolderPath=new File(lProperties.getProperty("log4j.logpath"));

}

if(aConfigFile!=null && aConfigFile.trim().length()>0)

{

File lConfigFilePath=new File(lFolderPath.getAbsolutePath()+File.separator+aConfigFile);

lProperties.setProperty("log4j.appender.S1.File",lConfigFilePath.getAbsolutePath());

}

else

{

String defaultLog=lProperties.getProperty("log4j.appender.S1.File");

lProperties.setProperty("log4j.appender.S1.File",lFolderPath.getPath()+File.separator+defaultLog);

}

}

catch (Exception e) {

throw new RuntimeException("Error reading log4j.properties: " + e.toString());

}

finally {

if (lInputStream != null)

{

try {

lInputStream.close();

} catch (Throwable t) {}

}

}

PropertyConfigurator.configure(lProperties);

return Category.getInstance("ls3");

}//endof getCategory()

About | Sitemap | Contact