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 Shorn Tolley <sh...@yahoo.co.uk> on 2002/09/15 04:35:25 UTC

Using multiple Logger's to decide whether to log a message

Hi folks,

Currently, I have a util class for executing JDBC that
talks direct to my DB (we'll call it JDBCUtil). 
Methods on the JDBCUtil class get executed from
various other classes in our app.

When a problem occurs with the SQL, I don't want to
know that it was the JDBCUtil class where the error
occurred (I know that already), I want to know who
called it.  So all logging in the JDBCUtil methods is
done on a Logger instance that gets passed in as a
parameter to the method.

Now, for all debug logging, I want some flexibility on
whether or not my JDBCUtil debug log messages get
logged or not.  Basically, I want to be able to turn
off all JDBC debug logging *without* turning off all
debug logging in all the classes that call JDBCUtil.

So, what I have done is define a Logger instance in
JDBCUtil and all debug logging in JDBCUtil goes
through a method that does the following:

public void debugSQL(
  Logger passedInLogger, 
  String sqlStatment, 
  List params)
{
  if( 
    JDBCUtil.logger.isDebugEnabled() && 
    passedInLogger.isDebugEnabled()
  ){
    // do logging
  }
}

JDBCUtil.logger is never used for logging, it is only
used for deciding whether or not debug logging will be
done.

This setup allows me to turn off all debug logging in
JDBCUtil without turning off debug logging in all the
calling classes.  It also still allows me to turn off
debug logging for individual calling classes.

What it doesn't allow me to do is selectively turn on
JDBCUtil debug logging for only only caller while
having the others turned off.  (Unless of course, I
turn off  debug logging for all the other callers and
turn on debug logging in JDBCUtil.  But that's no
worse than before I implemented this scheme). 

What I'm asking for is feedback on this scheme.  Is
there a better way to do what I'm trying to do?  Are
there any obvious faults with the scheme?  Could I
implement something similar with filtering and
whatnot?


Cheers,
Shorn.


__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>