diff options
author | Barry Lind <barry@xythos.com> | 2002-06-11 02:55:16 +0000 |
---|---|---|
committer | Barry Lind <barry@xythos.com> | 2002-06-11 02:55:16 +0000 |
commit | b465f5307f9f5506beb1edbcc0fb56eed7c29c12 (patch) | |
tree | 8b9c3b3635d22ac8e0983c28ba761ca231469c05 /src/interfaces/jdbc/org/postgresql/Driver.java.in | |
parent | 8d1c1d40ec25424d08539cdd358cfcc437adeb63 (diff) | |
download | postgresql-b465f5307f9f5506beb1edbcc0fb56eed7c29c12.tar.gz |
The patch does the following:
Allows you to set the loglevel at runtime by adding ?loglevel=X to the connection URL, where 1 = INFO and 2 = DEBUG.
Automatically turns on logging by calling DriverManager.setPrintWriter(new PrintWriter(System.out)) if one is not already set.
Adds a Driver.info() message that prints out the version number
Adds member variables logDebug and logInfo that can be checked before making logging methods calls
Adds a build number to the version number string. This build number will need to be manually incremented when we see fit.
----------------------------------------------------------------------
Modified Files:
org/postgresql/Connection.java org/postgresql/Driver.java.in
org/postgresql/fastpath/Fastpath.java
org/postgresql/jdbc1/DatabaseMetaData.java
org/postgresql/jdbc2/Connection.java
org/postgresql/jdbc2/DatabaseMetaData.java
org/postgresql/largeobject/LargeObjectManager.java
org/postgresql/util/PSQLException.java
org/postgresql/util/Serialize.java
----------------------------------------------------------------------
Diffstat (limited to 'src/interfaces/jdbc/org/postgresql/Driver.java.in')
-rw-r--r-- | src/interfaces/jdbc/org/postgresql/Driver.java.in | 124 |
1 files changed, 25 insertions, 99 deletions
diff --git a/src/interfaces/jdbc/org/postgresql/Driver.java.in b/src/interfaces/jdbc/org/postgresql/Driver.java.in index bc1925efe5..a199fe2bc7 100644 --- a/src/interfaces/jdbc/org/postgresql/Driver.java.in +++ b/src/interfaces/jdbc/org/postgresql/Driver.java.in @@ -29,13 +29,10 @@ public class Driver implements java.sql.Driver // make these public so they can be used in setLogLevel below - public static final int DEBUG = 0; + public static final int DEBUG = 2; public static final int INFO = 1; - public static final int WARN = 2; - public static final int ERROR = 3; - public static final int FATAL = 4; - - private static int logLevel = FATAL; + public static boolean logDebug = false; + public static boolean logInfo = false; static { @@ -46,7 +43,6 @@ public class Driver implements java.sql.Driver // my early jdbc work did - and that was based on other examples). // Placing it here, means that the driver is registered once only. java.sql.DriverManager.registerDriver(new Driver()); - } catch (SQLException e) { @@ -106,7 +102,12 @@ public class Driver implements java.sql.Driver * to/from the database to unicode. If multibyte is enabled on the * server then the character set of the database is used as the default, * otherwise the jvm character encoding is used as the default. - * compatible - This is used to toggle + * loglevel - (optional) Enable logging of messages from the driver. + * The value is an integer from 1 to 2 where: + * INFO = 1, DEBUG = 2 + * The output is sent to DriverManager.getPrintWriter() if set, + * otherwise it is sent to System.out. + * compatible - (optional) This is used to toggle * between different functionality as it changes across different releases * of the jdbc driver code. The values here are versions of the jdbc * client and not server versions. For example in 7.1 get/setBytes @@ -140,12 +141,12 @@ public class Driver implements java.sql.Driver { if ((props = parseURL(url, info)) == null) { - Driver.debug("Error in url" + url); + if (Driver.logDebug) Driver.debug("Error in url" + url); return null; } try { - Driver.debug("connect " + url); + if (Driver.logDebug) Driver.debug("connect " + url); org.postgresql.Connection con = (org.postgresql.Connection)(Class.forName("@JDBCCONNECTCLASS@").newInstance()); con.openConnection (host(), port(), props, database(), url, this); @@ -153,7 +154,7 @@ public class Driver implements java.sql.Driver } catch (ClassNotFoundException ex) { - Driver.debug("error", ex); + if (Driver.logDebug) Driver.debug("error", ex); throw new PSQLException("postgresql.jvm.version", ex); } catch (PSQLException ex1) @@ -164,7 +165,7 @@ public class Driver implements java.sql.Driver } catch (Exception ex2) { - Driver.debug("error", ex2); + if (Driver.logDebug) Driver.debug("error", ex2); throw new PSQLException("postgresql.unusual", ex2); } } @@ -251,7 +252,7 @@ public class Driver implements java.sql.Driver */ public static String getVersion() { - return "@VERSION@"; + return "@VERSION@ jdbc driver build " + m_buildNumber; } /* @@ -293,12 +294,6 @@ public class Driver implements java.sql.Driver { String token = st.nextToken(); - // PM June 29 1997 - // Added this, to help me understand how this works. - // Unless you want each token to be processed, leave this commented out - // but don't delete it. - //DriverManager.println("wellFormedURL: state="+state+" count="+count+" token='"+token+"'"); - // PM Aug 2 1997 - Modified to allow multiple backends if (count <= 3) { @@ -379,7 +374,6 @@ public class Driver implements java.sql.Driver else if (state == -5) { value = token; - //DriverManager.println("put("+key+","+value+")"); urlProps.put(key, value); state = -2; } @@ -387,13 +381,6 @@ public class Driver implements java.sql.Driver } } - // PM June 29 1997 - // This now outputs the properties only if we are logging - // PM Sep 13 1999 Commented out, as it throws a Deprecation warning - // when compiled under JDK1.2. - //if (DriverManager.getLogStream() != null) - // urlProps.list(DriverManager.getLogStream()); - return urlProps; } @@ -446,12 +433,13 @@ public class Driver implements java.sql.Driver * used to turn logging on to a certain level, can be called * by specifying fully qualified class ie org.postgresql.Driver.setLogLevel() * @param int logLevel sets the level which logging will respond to - * FATAL being almost no messages + * INFO being almost no messages * DEBUG most verbose */ public static void setLogLevel(int logLevel) { - Driver.logLevel = logLevel; + logDebug = (logLevel >= DEBUG) ? true : false; + logInfo = (logLevel >= INFO) ? true : false; } /* * logging message at the debug level @@ -459,7 +447,7 @@ public class Driver implements java.sql.Driver */ public static void debug(String msg) { - if (logLevel <= DEBUG) + if (logDebug) { DriverManager.println(msg); } @@ -470,7 +458,7 @@ public class Driver implements java.sql.Driver */ public static void debug(String msg, Exception ex) { - if (logLevel <= DEBUG) + if (logDebug) { DriverManager.println(msg + ex != null ? ex.getMessage() : "null Exception"); } @@ -481,7 +469,7 @@ public class Driver implements java.sql.Driver */ public static void info(String msg) { - if (logLevel <= INFO) + if (logInfo) { DriverManager.println(msg); } @@ -492,75 +480,13 @@ public class Driver implements java.sql.Driver */ public static void info(String msg, Exception ex) { - if (logLevel <= INFO) - { - DriverManager.println(msg + ex != null ? ex.getMessage() : "null Exception"); - } - } - /* - * logging message at warn level - * messages will be printed if the logging level is less or equal to WARN - */ - public static void warn(String msg) - { - if (logLevel <= WARN) - { - DriverManager.println(msg); - } - } - /* - * logging message at warn level - * messages will be printed if the logging level is less or equal to WARN - */ - public static void warn(String msg, Exception ex) - { - if (logLevel <= WARN) - { - DriverManager.println(msg + ex != null ? ex.getMessage() : "null Exception"); - } - } - /* - * logging message at error level - * messages will be printed if the logging level is less or equal to ERROR - */ - public static void error(String msg) - { - if (logLevel <= ERROR) - { - DriverManager.println(msg); - } - } - /* - * logging message at error level - * messages will be printed if the logging level is less or equal to ERROR - */ - public static void error(String msg, Exception ex) - { - if (logLevel <= ERROR) - { - DriverManager.println(msg + ex != null ? ex.getMessage() : "null Exception"); - } - } - /* - * logging message at fatal level - * messages will be printed if the logging level is less or equal to FATAL - */ - public static void fatal(String msg) - { - if (logLevel <= FATAL) - { - DriverManager.println(msg); - } - } - /* - * logging message at fatal level - * messages will be printed if the logging level is less or equal to FATAL - */ - public static void fatal(String msg, Exception ex) - { - if (logLevel <= FATAL) + if (logInfo) { DriverManager.println(msg + ex != null ? ex.getMessage() : "null Exception"); } } + + //The build number should be incremented for every new build + private static int m_buildNumber = 100; + } |