logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shiby Maria John" <Shi...@ibsplc.com>
Subject how to print line number
Date Fri, 12 May 2006 06:53:37 GMT
Hi,

I have a framework that implements the logging by log4j.
Now my classes need to log using this and I need to print the line
number from where the log originally originated from.

I will explain what I want with an example.
I have three classes which i am enclosing here.

TestLogging.java (Test class for Logger)
1 : import framework.logging.Logger;
2 : import framework.logging.Log;
3 : public class TestIflyLogging {
4 :   private static Logger log = Log.getLogger("TestLogging");
5 :   public static void main(String[] args) {
6 :         log.debug("Start of main");
7 :         log.info("Information");
8 :         ...
9 :   }
10 : }

Log.java
1 : package framework.logging;
2 : public class Log {
3 :   public static Logger getLogger(String className) {
4 :         return new Logger(className);
5 :   }
6 : }

Logger.java
1 : public class Logger {
2 :   org.apache.log4j.Logger cat;
3 :   Logger(String classname) {
4 :         if (classname == null) {
5 :               cat = org.apache.log4j.Logger.getRootLogger();
6 :         } else {
7 :               cat = org.apache.log4j.Logger.getLogger(classname);
8 :         }
9 :   }
10 :
11 :  public void debug(String message) {
12 :        cat.debug(message);
13 :  }
14 :
15 :  public void warn(String message) {
16 :        cat.warn(message);
17 :  }
18 :
19 :  public void error(String message) {
20 :        cat.error(message);
21 :  }
22 :
23 :  public void fatal(String message) {
24 :        cat.fatal(message);
25 :  }
26 :
27 :  public void info(String message) {
28 :        cat.info(message);
29 :  }
30 : }

This is my log4j.properties file.
# Set root logger level to DEBUG and its only appender to A1.
log4j.rootLogger=DEBUG, A1

# A1 is set to be a ConsoleAppender.
log4j.appender.A1=org.apache.log4j.ConsoleAppender

# A1 uses PatternLayout.
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%p: %l - %m%n

This is the output that I get when I run TestLogging.java :
DEBUG: framework.logging.Logger.debug(Logger.java:12) - Start of main
INFO: framework.logging.Logger.info(Logger.java:28) - Information

What I want is this output :
DEBUG: TestLogging.main(TestLogging.java:6) - Start of main
INFO: TestLogging.main(TestLogging.java:7) - Information

Is there any way to acheive this??

Thanks in advance,
Shiby





---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Mime
View raw message