dcsimg
log files in xml format
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   chinedu_Alum
Posted On:   Tuesday, March 8, 2005 12:22 AM

i want to log my request in different log files output how is this done using a RollingFileAppender and a patternLayout passing the the file full part and a layout as a parameter to the appender. this is my lines of code of logging to different files. public void logThis(Object obj){ //create a layout using a layout type PatternLayout layout= new PatternLayout("%d{ISO8601} [%t] %-5p %c %x - %m%n"); //set the Level of the logger logger.setLevel(Level.DEBUG); //create a console appender ConsoleAppender soleAppender = new ConsoleAppender(layout); //BasicConfigurator.configure(); logger.addAppender(soleAppender); //create and initialize file appenders    More>>

i want to log my request in different log files output
how is this done using a RollingFileAppender and a patternLayout passing the the file full part and a layout as a parameter to the appender.
this is my lines of code of logging to different files.

public void logThis(Object obj){
//create a layout using a layout type
PatternLayout layout= new PatternLayout("%d{ISO8601} [%t] %-5p %c %x - %m%n");
//set the Level of the logger
logger.setLevel(Level.DEBUG);
//create a console appender
ConsoleAppender soleAppender = new ConsoleAppender(layout);
//BasicConfigurator.configure();
logger.addAppender(soleAppender);
//create and initialize file appenders
RollingFileAppender rollAppender = null;
RollingFileAppender warnAppender = null;
RollingFileAppender errorAppender = null;
//check if u can log
if (logger.isDebugEnabled()){
logger.debug(obj + "note the info");

try
{
//set the output to the rootLogger console
rollAppender = new RollingFileAppender(layout,"c:\OutputA.xml",true);
rollAppender.setMaxFileSize("50KB");
rollAppender.setMaxBackupIndex(2);
}catch(Exception ex){}
logger.addAppender(rollAppender);
logger.info(obj + "move if this is more than capacity");
try {
//create a file appender
warnAppender = new RollingFileAppender(layout,"c:\OutputB.xml",true);
}catch (IOException e) {}
logger.addAppender(warnAppender);
logger.warn(obj + "this is it!");

try{
//create a file appender
errorAppender = new RollingFileAppender(layout,"c:\OutputC.xml",true);
}catch (IOException e1) {}
logger.addAppender(errorAppender);
logger.error(obj + ":" + "the program can still continue");
}else{
logger.fatal(obj + "stop the program");
}

}

   <<Less
About | Sitemap | Contact