Duplicate Entry while using log4j ... please run the code and check
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   ajith_prabhakar
Posted On:   Monday, March 17, 2003 03:18 AM

Please Try this piece of code public class MyLogeTester { public MyLogeTester() { super(); // TODO Auto-generated constructor stub } public static void main(String[] args) { FileLogger.responseLog("TEsting+REsponse"); FileLogger.requestLog("Testing+Request"); //FileLogger.responseLog("aTEsting"); //FileLogger.requestLog("aTesting"); } } import org.apache.log4j.Logger; import org.apache.log4j.FileAppender; import org.apache.log4j.PatternLayout; import org.apache.log4j.BasicConfigurator; import java.io.IOException; /** * @author Administrator *    More>>

Please Try this piece of code
public class MyLogeTester {


public MyLogeTester() {
super();
// TODO Auto-generated constructor stub
}

public static void main(String[] args) {
FileLogger.responseLog("TEsting+REsponse");
FileLogger.requestLog("Testing+Request");
//FileLogger.responseLog("aTEsting");
//FileLogger.requestLog("aTesting");
}
}

import org.apache.log4j.Logger;
import org.apache.log4j.FileAppender;
import org.apache.log4j.PatternLayout;
import org.apache.log4j.BasicConfigurator;
import java.io.IOException;

/**
* @author Administrator
*
* To change this generated comment go to
*
*/
public class FileLogger {





static void requestLog(String msg1){

String sfile_name = "requestlog.log";
Logger request_log;
PatternLayout pattern;
FileAppender app1;

request_log = Logger.getLogger(FileLogger.class.getName());
pattern = new PatternLayout();
pattern.setConversionPattern("%d %r [%t] %-5p %c - %m %n
");

try{
app1 = new FileAppender(pattern,sfile_name,true,false,500);
BasicConfigurator.configure(app1);
}
catch (IOException e){
System.err.println(e.getStackTrace());
}

request_log.info(msg1);
}


static void responseLog(String msg){

String sfile_name = "responselog.log";
Logger response_log;
PatternLayout pattern;
FileAppender app;

response_log = Logger.getLogger(FileLogger.class.getName());
pattern = new PatternLayout();

pattern.setConversionPattern("%d %r [%t] %-5p %c - %m %n
");
try{
app = new FileAppender(pattern,sfile_name,true,false,500);
BasicConfigurator.configure(app);
}
catch (IOException e){
System.err.println(e.getStackTrace());
}

response_log.info(msg);
}


}
Can u please tell me where am i going wrong as i am getting duplicate entries in the first method called from the first programs main()

   <<Less

Re: Duplicate Entry while using log4j ... please run the code and check

Posted By:   Christopher_Koenigsberg  
Posted On:   Monday, March 17, 2003 06:35 AM

You also seem to have a duplicate posting problem, too. And they're both unreadably unformatted.

About | Sitemap | Contact