Re: Log4J Ignores log4j.LogLevel



Mark Space wrote:
Lew wrote:

private static Log _apacheLog = null;
{
if( null == _myLogger )
{
_myLogger = new Logger();
}
}
return _myLogger;

From this we see that _myLogger will change every time the factory method is invoked. Why do you store the value in the static member and return it, both?

Well, the _myLogger variable is private, so how else would it be accessed? Looks like a Singleton pattern to me. _myLogger shouldn't change with each invocation; it's only assigned when _myLogger is null to begin with, unless I'm missing something.

You are right, I missed that. Of course, log4j will always deliver the same Logger if you pass the same Class or String to the Logger factory anyway, so I'm questioning again why the need to provide a custom factory class.

The configuration of the Logger would be much easier to understand (for me, at least) if the Logger in question were log4j's. So I reiterate my suggestion that the OP use the log4j Logger class and its factory method.

--
Lew
.



Relevant Pages

  • Re: Log4J Ignores log4j.LogLevel
    ... From this we see that _myLogger will change every time the factory ... Looks like a Singleton pattern to me. ... same Logger if you pass the same Class or String to the Logger factory ...
    (comp.lang.java.help)
  • Re: Not understandable Thread behaviour
    ... but my crystal ball tells me that MyLogger ... > both Logger and Thread. ... > If there were no Runnable interface and extending Thread ... I hadn't considered the inheritance issue before. ...
    (comp.lang.java.help)
  • Re: Log4J Ignores log4j.LogLevel
    ... the logging level is being ignored. ... The constructor tells us that your class name is Logger, which is also a log4j class name. ... Of which type is _myLogger? ...
    (comp.lang.java.help)
  • Re: Not understandable Thread behaviour
    ... it's not a good idea to extend Thread. ... but my crystal ball tells me that MyLogger ... both Logger and Thread. ... MyLogger object "is a" Logger object, ...
    (comp.lang.java.help)