How to use lo4j in wsad as a degugger? Can anyone can give me a simple example ?

Showing Answers 1 - 2 of 2 Answers

Rit

  • Jul 25th, 2005
 

run this file, i think result will itself explain you the use of LOG4J. otherwise mail me ritesh.patni@gmail.com :- 
package com.banking.log4j; 
import org.apache.log4j.*; 
 
import com.lnt.banking.constant.ConstantIf; 
public class TestLogging { 
static Logger cat = Logger.getLogger(ConstantIf.LOG4JKEY); 
static Logger cat1 = Logger.getLogger("com.foo"); 
//static Logger cat1 = (Logger) Logger.getInstance(TestLogging.class.getName()); 
static 

BasicConfigurator.configure(); 
try { 
cat.setLevel(Level.ERROR); 
cat1.setLevel(Level.DEBUG); 
cat1.addAppender(new RollingFileAppender(new HTMLLayout(),ConstantIf.dest1)); 
} catch (Exception e) { 
cat.fatal("The Exception is : ",e); 

finally 

cat1.fatal("The Exception is : "); 
cat.fatal("The Exception is : "); 


public static void main(String[] args) { 
System.out.println(args.length); 
cat1.debug("Start of the MAIN()-- CAT1"); 
cat1.info("This is Testing for the INFO method()-- CAT1"); 
cat1.warn("This is Testing for the WARN method()-- CAT1"); 
cat1.error("This is Testing for the ERROR method()-- CAT1"); 
cat1.fatal("This is Testing for the fatal method()-- CAT1"); 
cat.debug("Start of the MAIN()"); 
cat.info("This is Testing for the INFO method()"); 
cat.warn("This is Testing for the WARN method()"); 
cat.error("This is Testing for the ERROR method()"); 
cat.fatal("This is Testing for the fatal method()"); 
new TestLogging().init(); 

public void init(){ 
java.util.Properties prop = System.getProperties(); 
java.util.Enumeration enum = prop.propertyNames(); 
 
cat.info("*******System Enviroment As seen by Java ****"); 
cat.debug("******Format : PROPERTY + VALUE *****"); 
try 

throw new Exception("exception "); 

catch(Exception e) 

cat.error("This is new Error",e); 

finally 

cat1.info("You Are at the end of the INIT() of the TestLogging class"); 
cat.info("You Are at the end of the INIT() of the TestLogging class"); 

 


  Was this answer useful?  Yes

Muhammad Sajjad Awan

  • Jul 25th, 2005
 

there are few step to use Log4J in you java code. 
1- creat a file name log.properties with following text 
log4j.rootLogger=debug, stdout, R 
 
log4j.appender.stdout=org.apache.log4j.ConsoleAppender 
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 
 
# Pattern to output the caller's file name and line number. 
log4j.appender.stdout.layout.ConversionPattern=%5p %d{dd MMM yyyy HH:mm:ss,SSS} (%F:%L) - %m%n 
 
log4j.appender.R=org.apache.log4j.RollingFileAppender 
log4j.appender.R.File=c:out.log 
 
log4j.appender.R.MaxFileSize=1024KB 
# Keep one backup file 
log4j.appender.R.MaxBackupIndex=1 
 
log4j.appender.R.layout=org.apache.log4j.PatternLayout 
log4j.appender.R.layout.ConversionPattern=%5p %d{dd MMM yyyy HH:mm:ss,SSS} (%F:%L) - %m%n 
 
 
2- import package import org.apache.log4j.*; 
3- PropertyConfigurator.configure(log.properties file path shuld be here);-  
4- logger = Logger.getLogger(ClassName.class); 
5- logger.debug(" any message you want to display"); 

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions