You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by "Lilianne E. Blaze" <li...@tlen.pl> on 2006/11/09 13:28:13 UTC
[Commons-logging] Small patch to make debugging easier
Hello,
During the last few days I had major problems trying to configure
Commons-Logging + Log4j on Glassfish.
It turned out to be related to Log4j UDPAppender, but it took me
needlessly long time to verify the problem was indeed in Log4j and not
in Commons-Logging, Glassfish or something else. Now, why am I posting
it here then - I made a small modification which logs Log4j failures
more precisely, instead of just:
[LogFactoryImpl@14810083 from
org.apache.catalina.loader.WebappClassLoader@1904280] Could not
instantiate Log 'org.apache.commons.logging.impl.Log4JLogger' --
java.lang.reflect.InvocationTargetException: null
which explains, basically, nothing, you get for example:
[LogFactoryImpl@14810083 from
org.apache.catalina.loader.WebappClassLoader@1904280] Could not
instantiate Log 'org.apache.commons.logging.impl.Log4JLogger' --
java.lang.reflect.InvocationTargetException: null
[LogFactoryImpl@14810083 from
org.apache.catalina.loader.WebappClassLoader@1904280] ...
InvocationTargetException: java.lang.ExceptionInInitializerError: null
[LogFactoryImpl@14810083 from
org.apache.catalina.loader.WebappClassLoader@1904280] ...
ExceptionInInitializerError: java.lang.IllegalStateException: Property
layout must be set for UDPAppender named appenderLocalhostUdp
which states clearly that Log4j was indeed loaded, and the problem was
in its configuration.
All it does is expand those two exceptions if they occurred. It could be
more general and more elegant, but this code should work in pre-1.4 Java.
Could you please include it in next build of Commons-Logging?
Attaching the patch text below.
Greetings, Lilianne E. Blaze
Index: LogFactoryImpl.java
***
D:\Work\Projects\Apache\commons-logging-custom\src\org\apache\commons\logging\impl\LogFactoryImpl.java
Base (BASE)
---
D:\Work\Projects\Apache\commons-logging-custom\src\org\apache\commons\logging\impl\LogFactoryImpl.java
Locally Modified (Based On LOCAL)
***************
*** 1362,1369 ****
--- 1362,1388 ----
+ logAdapterClassName + "' -- "
+ discoveryFlaw.getClass().getName() + ": "
+ discoveryFlaw.getLocalizedMessage());
+
+ if ( discoveryFlaw instanceof InvocationTargetException ) {
+ InvocationTargetException ite =
(InvocationTargetException)discoveryFlaw;
+ Throwable cause = ite.getTargetException();
+ logDiagnostic("... InvocationTargetException: " +
+ cause.getClass().getName() + ": " +
+ cause.getLocalizedMessage());
+
+ if( cause instanceof ExceptionInInitializerError ) {
+ ExceptionInInitializerError eiie =
(ExceptionInInitializerError)cause;
+ Throwable cause2 = eiie.getException();
+ logDiagnostic("... ExceptionInInitializerError: " +
+ cause2.getClass().getName() + ": " +
+ cause2.getLocalizedMessage());
+
}
+ }
+
+ }
+
if (!allowFlawedDiscovery) {
throw new LogConfigurationException(discoveryFlaw);
}
Index: Log4JLogger.java
***
D:\Work\Projects\Apache\commons-logging-custom\src\org\apache\commons\logging\impl\Log4JLogger.java
Base (BASE)
---
D:\Work\Projects\Apache\commons-logging-custom\src\org\apache\commons\logging\impl\Log4JLogger.java
Locally Modified (Based On LOCAL)
***************
*** 77,84 ****
--- 77,86 ----
// ------------------------------------------------------------
static {
+
if (!Priority.class.isAssignableFrom(Level.class)) {
// nope, this is log4j 1.3, so force an
ExceptionInInitializerError
+ // note - it still works with log4j 1.3.8-alpha
throw new InstantiationError("Log4J 1.2 not available");
}
***************
*** 112,117 ****
--- 114,124 ----
/** For use with a log4j factory.
*/
public Log4JLogger(Logger logger ) {
+
+ if( logger == null ) {
+ throw new IllegalArgumentException("Warning - logger ==
null, possible Log4j misconfiguration?");
+ }
+
this.name = logger.getName();
this.logger=logger;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
Re: [Commons-logging] Small patch to make debugging easier
Posted by Sandy McArthur <sa...@apache.org>.
You're best bet is to attach your patch to a issue at
https://issues.apache.org/jira/browse/LOGGING and then either be
patient or try to get a committer to take interests in your submission
and consider it.
Posting to the mailing list means you're taking a chance that it won't
get noticed by someone who chooses to work on commons logging. Also,
since no one I know around here is paid to work at Apache, things can
seem to be ignored for a long while until someone finds the time and
energy to address your issue.
On 11/14/06, Lilianne E. Blaze <li...@tlen.pl> wrote:
> Why the complete lack of response?
> If something like that was in the code earlier, it would save me a good
> couple of hours, so I believe it is useful enough to be included. I
> can't be the only one who encountered this problem.
>
> Or is it the wrong list?
>
> Greetings, Lilianne E. Blaze
>
> Lilianne E. Blaze wrote:
> > Hello,
> > During the last few days I had major problems trying to configure
> > Commons-Logging + Log4j on Glassfish.
> > It turned out to be related to Log4j UDPAppender, but it took me
> > needlessly long time to verify the problem was indeed in Log4j and not
> > in Commons-Logging, Glassfish or something else. Now, why am I posting
> > it here then - I made a small modification which logs Log4j failures
> > more precisely, instead of just:
> >
> > [LogFactoryImpl@14810083 from
> > org.apache.catalina.loader.WebappClassLoader@1904280] Could not
> > instantiate Log 'org.apache.commons.logging.impl.Log4JLogger' --
> > java.lang.reflect.InvocationTargetException: null
> >
> > which explains, basically, nothing, you get for example:
> >
> > [LogFactoryImpl@14810083 from
> > org.apache.catalina.loader.WebappClassLoader@1904280] Could not
> > instantiate Log 'org.apache.commons.logging.impl.Log4JLogger' --
> > java.lang.reflect.InvocationTargetException: null
> > [LogFactoryImpl@14810083 from
> > org.apache.catalina.loader.WebappClassLoader@1904280] ...
> > InvocationTargetException: java.lang.ExceptionInInitializerError: null
> > [LogFactoryImpl@14810083 from
> > org.apache.catalina.loader.WebappClassLoader@1904280] ...
> > ExceptionInInitializerError: java.lang.IllegalStateException: Property
> > layout must be set for UDPAppender named appenderLocalhostUdp
> >
> > which states clearly that Log4j was indeed loaded, and the problem was
> > in its configuration.
> > All it does is expand those two exceptions if they occurred. It could
> > be more general and more elegant, but this code should work in pre-1.4
> > Java.
> >
> > Could you please include it in next build of Commons-Logging?
> >
> > Attaching the patch text below.
> >
> > Greetings, Lilianne E. Blaze
> >
> > Index: LogFactoryImpl.java
> > ***
> > D:\Work\Projects\Apache\commons-logging-custom\src\org\apache\commons\logging\impl\LogFactoryImpl.java
> > Base (BASE)
> > ---
> > D:\Work\Projects\Apache\commons-logging-custom\src\org\apache\commons\logging\impl\LogFactoryImpl.java
> > Locally Modified (Based On LOCAL)
> > ***************
> > *** 1362,1369 ****
> > --- 1362,1388 ----
> > + logAdapterClassName + "' -- "
> > + discoveryFlaw.getClass().getName() + ": "
> > + discoveryFlaw.getLocalizedMessage());
> > + + if ( discoveryFlaw instanceof
> > InvocationTargetException ) {
> > + InvocationTargetException ite =
> > (InvocationTargetException)discoveryFlaw;
> > + Throwable cause = ite.getTargetException();
> > + logDiagnostic("... InvocationTargetException: " +
> > + cause.getClass().getName() + ": " +
> > + cause.getLocalizedMessage());
> > + + if( cause instanceof
> > ExceptionInInitializerError ) {
> > + ExceptionInInitializerError eiie =
> > (ExceptionInInitializerError)cause;
> > + Throwable cause2 = eiie.getException();
> > + logDiagnostic("... ExceptionInInitializerError: " +
> > + cause2.getClass().getName() + ": " +
> > + cause2.getLocalizedMessage());
> > + }
> > + }
> > + + }
> > + if (!allowFlawedDiscovery) {
> > throw new LogConfigurationException(discoveryFlaw);
> > }
> >
> > Index: Log4JLogger.java
> > ***
> > D:\Work\Projects\Apache\commons-logging-custom\src\org\apache\commons\logging\impl\Log4JLogger.java
> > Base (BASE)
> > ---
> > D:\Work\Projects\Apache\commons-logging-custom\src\org\apache\commons\logging\impl\Log4JLogger.java
> > Locally Modified (Based On LOCAL)
> > ***************
> > *** 77,84 ****
> > --- 77,86 ----
> > // ------------------------------------------------------------
> >
> > static {
> > +
> > if (!Priority.class.isAssignableFrom(Level.class)) {
> > // nope, this is log4j 1.3, so force an
> > ExceptionInInitializerError
> > + // note - it still works with log4j 1.3.8-alpha
> > throw new InstantiationError("Log4J 1.2 not available");
> > }
> > ***************
> > *** 112,117 ****
> > --- 114,124 ----
> > /** For use with a log4j factory.
> > */
> > public Log4JLogger(Logger logger ) {
> > + + if( logger == null ) {
> > + throw new IllegalArgumentException("Warning - logger ==
> > null, possible Log4j misconfiguration?");
> > + }
> > + this.name = logger.getName();
> > this.logger=logger;
> > }
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> >
> >
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>
>
--
Sandy McArthur
"He who dares not offend cannot be honest."
- Thomas Paine
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
Re: [Commons-logging] Small patch to make debugging easier
Posted by "Lilianne E. Blaze" <li...@tlen.pl>.
Why the complete lack of response?
If something like that was in the code earlier, it would save me a good
couple of hours, so I believe it is useful enough to be included. I
can't be the only one who encountered this problem.
Or is it the wrong list?
Greetings, Lilianne E. Blaze
Lilianne E. Blaze wrote:
> Hello,
> During the last few days I had major problems trying to configure
> Commons-Logging + Log4j on Glassfish.
> It turned out to be related to Log4j UDPAppender, but it took me
> needlessly long time to verify the problem was indeed in Log4j and not
> in Commons-Logging, Glassfish or something else. Now, why am I posting
> it here then - I made a small modification which logs Log4j failures
> more precisely, instead of just:
>
> [LogFactoryImpl@14810083 from
> org.apache.catalina.loader.WebappClassLoader@1904280] Could not
> instantiate Log 'org.apache.commons.logging.impl.Log4JLogger' --
> java.lang.reflect.InvocationTargetException: null
>
> which explains, basically, nothing, you get for example:
>
> [LogFactoryImpl@14810083 from
> org.apache.catalina.loader.WebappClassLoader@1904280] Could not
> instantiate Log 'org.apache.commons.logging.impl.Log4JLogger' --
> java.lang.reflect.InvocationTargetException: null
> [LogFactoryImpl@14810083 from
> org.apache.catalina.loader.WebappClassLoader@1904280] ...
> InvocationTargetException: java.lang.ExceptionInInitializerError: null
> [LogFactoryImpl@14810083 from
> org.apache.catalina.loader.WebappClassLoader@1904280] ...
> ExceptionInInitializerError: java.lang.IllegalStateException: Property
> layout must be set for UDPAppender named appenderLocalhostUdp
>
> which states clearly that Log4j was indeed loaded, and the problem was
> in its configuration.
> All it does is expand those two exceptions if they occurred. It could
> be more general and more elegant, but this code should work in pre-1.4
> Java.
>
> Could you please include it in next build of Commons-Logging?
>
> Attaching the patch text below.
>
> Greetings, Lilianne E. Blaze
>
> Index: LogFactoryImpl.java
> ***
> D:\Work\Projects\Apache\commons-logging-custom\src\org\apache\commons\logging\impl\LogFactoryImpl.java
> Base (BASE)
> ---
> D:\Work\Projects\Apache\commons-logging-custom\src\org\apache\commons\logging\impl\LogFactoryImpl.java
> Locally Modified (Based On LOCAL)
> ***************
> *** 1362,1369 ****
> --- 1362,1388 ----
> + logAdapterClassName + "' -- "
> + discoveryFlaw.getClass().getName() + ": "
> + discoveryFlaw.getLocalizedMessage());
> + + if ( discoveryFlaw instanceof
> InvocationTargetException ) {
> + InvocationTargetException ite =
> (InvocationTargetException)discoveryFlaw;
> + Throwable cause = ite.getTargetException();
> + logDiagnostic("... InvocationTargetException: " +
> + cause.getClass().getName() + ": " +
> + cause.getLocalizedMessage());
> + + if( cause instanceof
> ExceptionInInitializerError ) {
> + ExceptionInInitializerError eiie =
> (ExceptionInInitializerError)cause;
> + Throwable cause2 = eiie.getException();
> + logDiagnostic("... ExceptionInInitializerError: " +
> + cause2.getClass().getName() + ": " +
> + cause2.getLocalizedMessage());
> + }
> + }
> + + }
> + if (!allowFlawedDiscovery) {
> throw new LogConfigurationException(discoveryFlaw);
> }
>
> Index: Log4JLogger.java
> ***
> D:\Work\Projects\Apache\commons-logging-custom\src\org\apache\commons\logging\impl\Log4JLogger.java
> Base (BASE)
> ---
> D:\Work\Projects\Apache\commons-logging-custom\src\org\apache\commons\logging\impl\Log4JLogger.java
> Locally Modified (Based On LOCAL)
> ***************
> *** 77,84 ****
> --- 77,86 ----
> // ------------------------------------------------------------
>
> static {
> +
> if (!Priority.class.isAssignableFrom(Level.class)) {
> // nope, this is log4j 1.3, so force an
> ExceptionInInitializerError
> + // note - it still works with log4j 1.3.8-alpha
> throw new InstantiationError("Log4J 1.2 not available");
> }
> ***************
> *** 112,117 ****
> --- 114,124 ----
> /** For use with a log4j factory.
> */
> public Log4JLogger(Logger logger ) {
> + + if( logger == null ) {
> + throw new IllegalArgumentException("Warning - logger ==
> null, possible Log4j misconfiguration?");
> + }
> + this.name = logger.getName();
> this.logger=logger;
> }
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org