0

I am trying to change the logging level to stop showing millions of this:

<May 26, 2010 10:26:02 AM EDT> <Debug> <JDBCDriverLogging> <000000> <2336: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 |                |> 

I have tried adding this to my java line:

-Djava.util.logging.config.file=/foo/bar/logging.properties

With this as my logging.properties file:

handlers = java.util.logging.ConsoleHandler
.level = OFF
java.util.logging.ConsoleHandler.level = INFO

No luck. I have tried this:

Logger logger = Logger.getLogger("com.microsoft.sqlserver.jdbc");
Handler handler = new ConsoleHandler();
handler.setLevel(Level.INFO);
logger.addHandler(handler);
logger.setLevel(Level.INFO);
logger.setUseParentHandlers(false);

No luck. I have searched around and all ideas center around one of these two options, so I must be doing something else wrong

I am using jtds-1.2.2.jar.

Thanks for any suggestions.

Scott
  • 75
  • 1
  • 9

2 Answers2

1
net.sourceforge.jtds.util.Logger.setLogWriter(new NullPrintWriter()) 

disables logging the Driver. The NullPrintWriter can be either found in the Apache Commons IO package, or implemented for yourself simple by extending PrintStream and replacing the print ops with no ops.

Daniel
  • 27,718
  • 20
  • 89
  • 133
  • Well, put your line in the logging.properties file but there was no change. – Scott Jun 09 '10 at 12:47
  • Then I assume the driver does not use the typical Loggername=Class convention, but logs into a logger named "JDBCDriverLogging". So you would have to add the line "JDBCDriverLogging.level=FATAL". Please respond how this worked out for you. – Daniel Jun 09 '10 at 17:29
  • Well, I tried this in both the logging properties file and in the code, no luck. Not sure if this matters, but this is the first debug line in the log: <000000> Thanks for your continued help. – Scott Jun 10 '10 at 21:45
  • Switch to Log4J. If log4J is enabled, all java.util.logging aware components will use log4j automatically AFAIK. I used log4j very successful imost of my projects and the config file is easy to setup. – Daniel Jun 11 '10 at 06:01
  • Well, I think it is the jTDS database driver that is doing the logging, not application code. So I don't know how I could get the driver to use log4j. Here is the home page: http://jtds.sourceforge.net/ – Scott Jun 11 '10 at 11:55
  • So, if you log something for yourself, the format differs? Why don't you just look in the jTDS source and see how they are logging? – Daniel Jun 11 '10 at 16:26
  • I did, and I see this in the Logger.setActive() method: @deprecated Use the JDBC standard mechanisms to enable logging. I guess I can tweak the source and use a modified version of jTDS, but it really should not be this hard. – Scott Jun 11 '10 at 18:06
1

Well I doubt you need this now but I came to your question trying to find a way to activate jTDS logging, the opposite to what you needed.

The only way I can find to get the logging to work is to hard-code a Logger like in this question: Log4J: How do I redirect an OutputStream or Writer to logger's writer(s)? and to pass it in to jTDS's Logger.setLogWriter():

    PrintWriter logger = new PrintWriter(
            new LogOutputStream(
                    LoggerFactory.getLogger(Logger.class),
                    Level.DEBUG));
    Logger.setLogWriter(logger);

Maybe in 6 years' time someone else will find this useful ;)

Community
  • 1
  • 1
Adam
  • 5,215
  • 5
  • 51
  • 90