You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Shai Wolf <sh...@coridan.com> on 2006/03/08 12:57:46 UTC

commons-logging discovery process

Hi,

 

This is my first post, and I hope I am doing it right.

If I do something wrong please notify me.

 

I am using commons-logging 1.0.3.

In my code I need to know whether the commons-logging was initialized or
not.

I know there is a detection process that looks for a log implementation.

How can I know programmatically that the process ended, succeeded, failed
etc.?

I didn't find any clue about it in the documentation or in the javadocs.

 

I hope you can help me with this one.

 

Regards,

Shai

 


RE: commons-logging discovery process

Posted by Simon Kitching <sk...@apache.org>.
> > > Von: "Shai Wolf" <sh...@coridan.com>
> > > Generally, I understand what you're saying.
> > > However, I still don't understand why commons-logging can't supply an
> > > indication on whether it detected a logging implementation or not. This
> > > indication should not be platform dependant, but it should be managed by
> > > the commons-logging layer only.

By the way, just in case you didn't realise it these messages:

log4j:WARN No appenders could be found for logger (Logger_Name).
log4j:WARN Please initialize the log4j system properly.

are output by log4j, NOT by commons-logging. 

Commons-logging successfully found the log4j installation, successfully
created an org.apache.log4j.Logger object and successfully called the
debug(msg) method (or whatever) on it. Log4j then detected that this was
the first call to it, tried to find its config, couldn't find it so
printed the message.

As far as commons-logging is concerned, everything went fine. All log4j
calls it made succeeded.

Regards,

Simon


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


RE: commons-logging discovery process

Posted by Simon Kitching <sk...@apache.org>.
On Wed, 2006-03-08 at 15:11 +0100, Boris Unckel wrote:
> Hi,
> > Von: "Shai Wolf" <sh...@coridan.com>
> > Generally, I understand what you're saying.
> > However, I still don't understand why commons-logging can't supply an
> > indication on whether it detected a logging implementation or not. This
> > indication should not be platform dependant, but it should be managed by
> > the commons-logging layer only.
> no thats not correct. It could offer an indication if it has detected a
> logging implementation. It detects classloader issues already.
> But it cannot offer an indicator wheter the underlying log API is properly
> configured or not. So the indicator would be JCL specific and not give a
> hint about the full chain.
> 

I agree with Boris' comments.

Note though that when commons-logging's "auto-detect" feature is used,
it *always* detects a logging implementation of some kind; the SimpleLog
implementation is included in commons-logging.jar and is "discovered" if
nothing else is available.

What you are asking (as Boris noted) is for information about whether
the implementation used by commons-logging (whether discovered or
explicitly specified) correctly managed to auto-configure itself. That's
not generally information that underlying logging libraries make
available. As far as I know, log4j's API doesn't provide any mechanism
for detecting that, nor java.util.logging.

In any case, the commons-logging documentation makes clear that
commons-logging does *not* set up or shut down logging libraries; that's
NOT within the scope of the project. The fact that most logging
libraries do auto-configure themselves is a bonus. However in
*principle* your code is required to initialise whatever concrete
logging library is available before any calls to commons-logging APIs
are made. As you appear to *know* that log4j is the library in use,
there's nothing stopping you explicitly configuring (and testing) log4j
in your startup code, before any commons-logging calls are made.

Note also that auto-detect is not always the best option; placing a
commons-logging.properties file in the classpath which specifies which
underlying library to use is more reliable and recommended whenever you
*know* what lib you want to use. As you know log4j is available, a
commons-logging.properties file that specifies
  org.apache.commons.logging.Log =
    org.apache.commons.logging.impl.Log4JLogger
to bypass auto-detect would also be a good idea.

Regards,

Simon


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


RE: commons-logging discovery process

Posted by Boris Unckel <bo...@gmx.net>.
Hi,
> Von: "Shai Wolf" <sh...@coridan.com>
> Generally, I understand what you're saying.
> However, I still don't understand why commons-logging can't supply an
> indication on whether it detected a logging implementation or not. This
> indication should not be platform dependant, but it should be managed by
> the commons-logging layer only.
no thats not correct. It could offer an indication if it has detected a
logging implementation. It detects classloader issues already.
But it cannot offer an indicator wheter the underlying log API is properly
configured or not. So the indicator would be JCL specific and not give a
hint about the full chain.

Regards
Boris

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


RE: commons-logging discovery process

Posted by Shai Wolf <sh...@coridan.com>.
I need this because I use another logging mechanism as long as the
commons-logging isn't configured/loaded/initialized. Later, I switch to the
commons-logging mechanism. That's why I need this API.
Generally, I understand what you're saying.
However, I still don't understand why commons-logging can't supply an
indication on whether it detected a logging implementation or not. This
indication should not be platform dependant, but it should be managed by the
commons-logging layer only.
Maybe I just don't know enough about the architecture of this service.
Anyway, thank you very much for your help.
Cheers,
Shai



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


RE: commons-logging discovery process

Posted by Boris Unckel <bo...@gmx.net>.
> Von: "Shai Wolf" <sh...@coridan.com>
> Regarding your answer, I read the documentation of the latest release and
> I
> still didn't find a way to know the detection status PROGRAMMATICALLY.
There is no way to check it programmatically. One workaround just for JCL:
boolean noError = true;
try {
LogFactory.getLogFactory();
Log myTestLog = LogFactory.getLog("foo.test");
myTestLog.debug("test");
} catch (Exception e) {
 e.printStacktrace();
 noError = false;
}
But this would just work for JCL and NOT the underlying log API.

> That
> means that I am looking for an API method to check the initialization
> state
> E.g. isInitiated() or hasAppenders(). Something that will tell me it's ok
> to
> start calling Log.info() and so on. It can also be an attribute that was
> set
> during the initialization.
There is no method/attribute as I know.

> Currently, if I call this method when no appenders are set, I will get the
> message (when using log4j):
> log4j:WARN No appenders could be found for logger (Logger_Name).
> log4j:WARN Please initialize the log4j system properly.
> 
> Is there a way to overcome this?
Even if log4j would offer a method like this it could not be in JCL because
JCL is meant to be log API _independent_.

In summary: There is currently no correct way to check the full chain of JCL
and the underlying log API programmatically.

Why do you need this? If you detect an error your programm can run without
log or terminate. The user/admin still must check why there is an error and 
she would have to lookup the System.out / System.err for this.

Regards
Boris

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


RE: commons-logging discovery process

Posted by Shai Wolf <sh...@coridan.com>.
Hi Boris,

Thank you for your comments. In order not to break this topic, I will start
putting the [component name] in my next topic.

Regarding your answer, I read the documentation of the latest release and I
still didn't find a way to know the detection status PROGRAMMATICALLY. That
means that I am looking for an API method to check the initialization state
E.g. isInitiated() or hasAppenders(). Something that will tell me it's ok to
start calling Log.info() and so on. It can also be an attribute that was set
during the initialization.
Currently, if I call this method when no appenders are set, I will get the
message (when using log4j):
log4j:WARN No appenders could be found for logger (Logger_Name).
log4j:WARN Please initialize the log4j system properly.

Is there a way to overcome this?

Regards,
Shai



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


Re: commons-logging discovery process

Posted by Boris Unckel <bo...@gmx.net>.
> Von: "Shai Wolf" <sh...@coridan.com>
> This is my first post, and I hope I am doing it right.
> 
> If I do something wrong please notify me.
Just a small notice: the policy of the list is to have
a [component] in the topic of the mail. In this case:
[logging] commons-logging discovery process

> I am using commons-logging 1.0.3.
This is an older release.
Have a look at the 1.1ReleaseCandidate
http://people.apache.org/~rdonkin/commons-logging/
and try this one out.

> How can I know programmatically that the process ended, succeeded, failed
> etc.?
> 
> I didn't find any clue about it in the documentation or in the javadocs.
> 
http://jakarta.apache.org/commons/logging/troubleshooting.html

Regards
Boris

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