logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "wleana" <wle...@yahoo.com>
Subject Re: static/inherit problem
Date Fri, 04 Apr 2003 01:38:25 GMT
I really don't think this should be the reason to make the Logger (or 
its wrapper) an instance variable of each class...this should be a 
fairly common problem , how do you guys handle it?

Do you have each class define and/or initialize its own Logger?
If you have a superclass and a subclass, does your subclass inherit 
superclass's Logger?


--- In Log4J@yahoogroups.com, "wleana" <wleana@y...> wrote:
> Hi, I have a design issue related to the fact that the Logger needs 
> to be static. And suppose I have A and its subclass B.
> I have a wrapper MyLog that wraps around Logger and a myId field of 
> each class, in which, the log message always print out myId of its 
> caller.
> class A {
> private static MyLog mLog;
> protected myId;
> A(){
>   myId = "A";
>   init myLog with myId...
> }
> public void doSth(String aMsg){
>    mLog.debug(aMsg);
> }
> } 
> class B extends A{
> B(){
>  myId = "B";
>  super()
>  }
> }
> When I do this:
> B b=new B();
> b.doSth("blah");
> The log will actually show the caller's myId is "A", instead of "B".
> (you see I even make the myId field non-static because of the same 
> issue, but actually I would like it to be static conceptually)
> I have tried different ways, it only works if mLog is not static, 
> within doSth from class A, it will actually dynamically use object 
> type B's mLog...But we want the Logger class (or its wrapper class) 
> to belong to class not to an object...how should we solve this? 
> should be the right design of this? Please share your thoughts. 
> Thanks a lot.
> -wleana
> --------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@j...
> For additional commands, e-mail: log4j-user-help@j...

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

View raw message