logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Stauffer" <stauffer.ja...@gmail.com>
Subject Re: Help - using a wrapper for log4j
Date Tue, 22 Aug 2006 11:58:03 GMT
There is a way to get the correct line numbers and it has been
discussed on the mailing list but I don't remember what it is so you
will need to search the archives.

Here are my suggestions in order of preference:
1. Just use log4j.  If you use a wrapper you lose some of the power of
log4j and then just couple your code to your wrapper instead of log4j.
2. If you really want to couple to something generic then use
commons-logging.  They have figured out those issues.
3. Reinvent the wheel.

On 8/22/06, chetan.v.minajagi@jpmchase.com
<chetan.v.minajagi@jpmchase.com> wrote:
> Hi,
>
> I have a class that holds a reference to Log4j's logger in it.I call this
> LoggerWrapper.
>
> The intention of using this and not Logger(log4j's Logger) directly is to
> keep my code as independent of  log4j as possible.
> This LoggerWrapper has methods called logDebug(Object description)
> i.e logXXX(Object description) for all 5 levels of logging.
>
> The implementation is very straight forward,like this
>
> logDebug(Object desc) {
>         logger.debug(desc); //logger is an instance of LoggerWrapper and
> of type org.apache.log4j.Logger
> }
>
> Now the problem.....
> In all my source code where there is a need to log i do it in this fashion
> LoggerWrapper.logDebug(Object  tobeLogged)
>
> In doing so the log files that are generated always have the first line as
> line #13,line #18 etc that refer to  where logger.xxx() methods are being
> used in LoggerWrapper's logXXX methods.
> This line number is of no help to me at all since it always gives me the
> LoggerWrapper's line number.
>
> What I actually need is that it should reflect the lines of the actual
> java file where i called LoggerWrapper.logDebug(Object tobeLogged)
>
>
> I have just pasted one such line from my log file here
> ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> 2006 08 01 16:33:14:072 BST DEBUG -
> com.jpmorgan.pathclear.siml.common.log.LoggerWrapper.logDebug(LoggerWrapper.java:66)
> -Setting ibatis template
> ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> Can you kindly tell me what I should do so that the line number that i get
> is the line from where i issued this debug statement and not the line
> number from my wrapper class.
>
> I am now not even sure that my approach was right although the intention
> behind was to be not too reliant on any particular implementation of
> logging.
>
> Look foward to solutions to tackle this problem.If there is a fundamental
> flaw in the way this has been designed look forward to some help in
> getting this sorted out.
>
> I could adopt Commons logging on top of log4j.That is one option.But is
> there a way to mend this itself so I get logs which are more
> informative(reflect the actual line nos) ?
>
> Regards,
> Chetan

-- 
James Stauffer        http://www.geocities.com/stauffer_james/
Are you good? Take the test at http://www.livingwaters.com/good/

---------------------------------------------------------------------
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