Example usage for java.sql DriverManager setLogStream

List of usage examples for java.sql DriverManager setLogStream

Introduction

In this page you can find the example usage for java.sql DriverManager setLogStream.

Prototype

@Deprecated(since = "1.2")
public static void setLogStream(java.io.PrintStream out) 

Source Link

Document

Sets the logging/tracing PrintStream that is used by the DriverManager and all drivers.

Usage

From source file:net.sourceforge.squirrel_sql.client.Application.java

@SuppressWarnings("deprecation")
private void setupJDBCLogging() {
    // If logging has changed.
    if (_jdbcDebugType != _prefs.getJdbcDebugType()) {
        final ApplicationFiles appFiles = new ApplicationFiles();
        final File outFile = appFiles.getJDBCDebugLogFile();

        // Close any previous logging.
        DriverManager.setLogStream(null);
        if (_jdbcDebugOutputStream != null) {
            _jdbcDebugOutputStream.close();
            _jdbcDebugOutputStream = null;
        }//from ww  w . j a v a 2  s .  c o  m
        DriverManager.setLogWriter(null);
        if (_jdbcDebugOutputWriter != null) {
            _jdbcDebugOutputWriter.close();
            _jdbcDebugOutputWriter = null;
        }

        if (_prefs.isJdbcDebugToStream()) {
            try {
                // i18n[Application.info.setjdbcdebuglog=Attempting to set JDBC debug log to output stream]
                s_log.debug(s_stringMgr.getString("Application.info.setjdbcdebuglog"));
                _jdbcDebugOutputStream = new PrintStream(new FileOutputStream(outFile));
                DriverManager.setLogStream(_jdbcDebugOutputStream);
                // i18n[Application.info.setjdbcdebuglogsuccess=JDBC debug log set to output stream
                // successfully]
                s_log.debug(s_stringMgr.getString("Application.info.setjdbcdebuglogsuccess"));
            } catch (IOException ex) {
                final String msg = s_stringMgr.getString("Application.error.jdbcstream");
                s_log.error(msg, ex);
                showErrorDialog(msg, ex);
                DriverManager.setLogStream(System.out);
            }
        }

        if (_prefs.isJdbcDebugToWriter()) {
            try {
                // i18n[Application.info.jdbcwriter=Attempting to set JDBC debug log to writer]
                s_log.debug(s_stringMgr.getString("Application.info.jdbcwriter"));
                _jdbcDebugOutputWriter = new PrintWriter(new FileWriter(outFile));
                DriverManager.setLogWriter(_jdbcDebugOutputWriter);
                // i18n[Application.info.jdbcwritersuccess=JDBC debug log set to writer successfully]
                s_log.debug(s_stringMgr.getString("Application.info.jdbcwritersuccess"));
            } catch (IOException ex) {
                final String msg = s_stringMgr.getString("Application.error.jdbcwriter");
                s_log.error(msg, ex);
                showErrorDialog(msg, ex);
                DriverManager.setLogWriter(new PrintWriter(System.out));
            }
        }

        _jdbcDebugType = _prefs.getJdbcDebugType();
    }
}