You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by BRUNO MELLONI <Br...@chickasaw.net> on 2012/01/11 23:56:34 UTC

Log4j and Java7/JDBC4.1's CommonDataSource.getParentLogger()

Just upgraded from Java 6 to Java 7 and got a nasty surprise.

I have a class that extends from JDBC's AbstractDataSource.  Java 7/JDBC4.1 requires implementing  the abstract method getParentLogger() from CommonDataSource.  The method returns a java.util.logging.Logger, but I use log4j.

I imagine that this problem has been encountered before and solved.

What is the best practice solution?


AW: forcing [root] logging - to a separate appender

Posted by Stadelmann Josef <jo...@axa-winterthur.ch>.
do you understand that log4j loggers work in a hierarchy?

	root
	com
	com.axa
	com.axa.ws
	com.axa.ws.spezpla
	com.axa.ws.spezpla.transport

Now
	com.axa.ws.spezpla.SpezplaService.java

	would become a logger named com.axa.ws.spezpla.SpezplaService
	and maybe at various levels in the hierarchy, you have loggers as well.

	now you can add 
	log4j.logger.com.axa.ws=INFO, TC_CONS, TC_ROLF, TC_FAP, TC_CHAINSAW
	to block that bad or too fine grained logging events from 
	com.axa.ws.spezpla.SpezplaService reach the root logger or any logger above com.axa.ws

by doing so you can intercept unwanted logging events on their way to the top root logger.

hope I got you right.
Josef	

-----Ursprüngliche Nachricht-----
Von: Sean A. [mailto:seanga2@gmail.com] 
Gesendet: Samstag, 7. April 2012 03:23
An: Log4J Users List
Betreff: Re: forcing [root] logging - to a separate appender

On 04/03/2012 11:24 AM, BRUNO MELLONI wrote:
> I support a server that uses log4j.  Of the many applications on it, a few dump their logs as [root] log4j entries.
>
> I would like to setup a category or even separate appender that allows me to control and/or separate these bad log entries.  The problem is that I only want to affect things "just at the root", not every single package in the server.
>
> How would I write such a category or appender configuration?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
	You could try implementing you own filter.  Have your class implement 
org.apache.log4j.spi.Filter, and implement the decide() method.  That 
gets passed a LoggingEvent, and you can look at getThreadName for root. 
  From there you'd need to add that filter in your config to whatever 
appender you'd like.
	Hope I understand the issue you're having here.  Maybe you could post 
some example log entries to clarify the problem.

		--Sean

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


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


Re: forcing [root] logging - to a separate appender

Posted by "Sean A." <se...@gmail.com>.
On 04/03/2012 11:24 AM, BRUNO MELLONI wrote:
> I support a server that uses log4j.  Of the many applications on it, a few dump their logs as [root] log4j entries.
>
> I would like to setup a category or even separate appender that allows me to control and/or separate these bad log entries.  The problem is that I only want to affect things "just at the root", not every single package in the server.
>
> How would I write such a category or appender configuration?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
	You could try implementing you own filter.  Have your class implement 
org.apache.log4j.spi.Filter, and implement the decide() method.  That 
gets passed a LoggingEvent, and you can look at getThreadName for root. 
  From there you'd need to add that filter in your config to whatever 
appender you'd like.
	Hope I understand the issue you're having here.  Maybe you could post 
some example log entries to clarify the problem.

		--Sean

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


forcing [root] logging - to a separate appender

Posted by BRUNO MELLONI <Br...@chickasaw.net>.
I support a server that uses log4j.  Of the many applications on it, a few dump their logs as [root] log4j entries.

I would like to setup a category or even separate appender that allows me to control and/or separate these bad log entries.  The problem is that I only want to affect things "just at the root", not every single package in the server.

How would I write such a category or appender configuration?

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


RE: Log4j and Java7/JDBC4.1's CommonDataSource.getParentLogger()

Posted by Douglas E Wegscheid <Do...@whirlpool.com>.
see http://www.slf4j.org/legacy.html

you are looking for "SLF4J bound to log4j with redirection of 
commons-logging and jul calls to SLF4J". See the section on jul-to-slf4j 
bridge, and the reference to SLF4JBridgeHandler javadocs. I would ask on 
one of the SLF4J groups for more details, if needed.

■ DOUGLAS E. WEGSCHEID // LEAD ENGINEER
(269) 923-5278 // Douglas_E_Wegscheid@whirlpool.com
"A wrong note played hesitatingly is a wrong note. A wrong note played 
with conviction is interpretation."

BRUNO MELLONI <Br...@chickasaw.net> wrote on 01/12/2012 11:19:57 
AM:

> I am not following.  I already have slf4j in my stack (needed by 
> other libraries), although I've written no code that directly 
> interacts with it.
> 
> I assume that you are telling me to implement getParentLogger() in 
> my datasource (so that it compiles in Java7) and that I should put a
> couple lines of code based on slf4j to get that parent logger so 
> that it really is reflecting the log4j logger. 
> 
> The obvious dumb question is... what would that code look like?
> 
> -----Original Message-----
> From: Douglas E Wegscheid [mailto:Douglas_E_Wegscheid@whirlpool.com] 
> Sent: Thursday, January 12, 2012 6:51 AM
> To: Log4J Users List
> Cc: log4j-user@logging.apache.org
> Subject: Re: Log4j and Java7/JDBC4.1's 
CommonDataSource.getParentLogger()
> 
> I have hit the same situation with software that requires use of 
> Apahce commons logging, I use slf4j (and have it feed log4j); it has
> adapters to let you log from j.u.l and commons logging. I don't know
> if it's best practice, but it certainly works.
> ■ DOUGLAS E. WEGSCHEID // LEAD ENGINEER
> (269) 923-5278 // Douglas_E_Wegscheid@whirlpool.com "A wrong note 
> played hesitatingly is a wrong note. A wrong note played with 
> conviction is interpretation."
> 
> 
> 
> BRUNO MELLONI <Br...@chickasaw.net>
> 01/11/2012 05:56 PM
> Please respond to
> "Log4J Users List" <lo...@logging.apache.org>
> 
> 
> To
> "log4j-user@logging.apache.org" <lo...@logging.apache.org>
> cc
> 
> Subject
> Log4j and Java7/JDBC4.1's CommonDataSource.getParentLogger()
> 
> 
> 
> 
> 
> 
> Just upgraded from Java 6 to Java 7 and got a nasty surprise.
> 
> I have a class that extends from JDBC's AbstractDataSource.  Java 
> 7/JDBC4.1 requires implementing  the abstract method getParentLogger() 
> from CommonDataSource.  The method returns a java.util.logging.Logger, 
but 
> I use log4j.
> 
> I imagine that this problem has been encountered before and solved.
> 
> What is the best practice solution?
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
> 


RE: Log4j and Java7/JDBC4.1's CommonDataSource.getParentLogger()

Posted by BRUNO MELLONI <Br...@chickasaw.net>.
I am not following.  I already have slf4j in my stack (needed by other libraries), although I've written no code that directly interacts with it.

I assume that you are telling me to implement getParentLogger() in my datasource (so that it compiles in Java7) and that I should put a couple lines of code based on slf4j to get that parent logger so that it really is reflecting the log4j logger.  

The obvious dumb question is... what would that code look like?

-----Original Message-----
From: Douglas E Wegscheid [mailto:Douglas_E_Wegscheid@whirlpool.com] 
Sent: Thursday, January 12, 2012 6:51 AM
To: Log4J Users List
Cc: log4j-user@logging.apache.org
Subject: Re: Log4j and Java7/JDBC4.1's CommonDataSource.getParentLogger()

I have hit the same situation with software that requires use of Apahce commons logging, I use slf4j (and have it feed log4j); it has adapters to let you log from j.u.l and commons logging. I don't know if it's best practice, but it certainly works.
■ DOUGLAS E. WEGSCHEID // LEAD ENGINEER
(269) 923-5278 // Douglas_E_Wegscheid@whirlpool.com "A wrong note played hesitatingly is a wrong note. A wrong note played with conviction is interpretation."



BRUNO MELLONI <Br...@chickasaw.net>
01/11/2012 05:56 PM
Please respond to
"Log4J Users List" <lo...@logging.apache.org>


To
"log4j-user@logging.apache.org" <lo...@logging.apache.org>
cc

Subject
Log4j and Java7/JDBC4.1's CommonDataSource.getParentLogger()






Just upgraded from Java 6 to Java 7 and got a nasty surprise.

I have a class that extends from JDBC's AbstractDataSource.  Java 
7/JDBC4.1 requires implementing  the abstract method getParentLogger() 
from CommonDataSource.  The method returns a java.util.logging.Logger, but 
I use log4j.

I imagine that this problem has been encountered before and solved.

What is the best practice solution?




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


Re: Log4j and Java7/JDBC4.1's CommonDataSource.getParentLogger()

Posted by Douglas E Wegscheid <Do...@whirlpool.com>.
I have hit the same situation with software that requires use of Apahce 
commons logging, I use slf4j (and have it feed log4j); it has adapters to 
let you log from j.u.l and commons logging. I don't know if it's best 
practice, but it certainly works.
■ DOUGLAS E. WEGSCHEID // LEAD ENGINEER
(269) 923-5278 // Douglas_E_Wegscheid@whirlpool.com
"A wrong note played hesitatingly is a wrong note. A wrong note played 
with conviction is interpretation."



BRUNO MELLONI <Br...@chickasaw.net> 
01/11/2012 05:56 PM
Please respond to
"Log4J Users List" <lo...@logging.apache.org>


To
"log4j-user@logging.apache.org" <lo...@logging.apache.org>
cc

Subject
Log4j and Java7/JDBC4.1's CommonDataSource.getParentLogger()






Just upgraded from Java 6 to Java 7 and got a nasty surprise.

I have a class that extends from JDBC's AbstractDataSource.  Java 
7/JDBC4.1 requires implementing  the abstract method getParentLogger() 
from CommonDataSource.  The method returns a java.util.logging.Logger, but 
I use log4j.

I imagine that this problem has been encountered before and solved.

What is the best practice solution?