@@ -27,6 +27,14 @@ import org.postgresql.util.PSQLException;
2727public class Driver implements java.sql.Driver
2828{
2929
30+ protected static final int DEBUG=0;
31+ protected static final int INFO = 1;
32+ protected static final int WARN = 2;
33+ protected static final int ERROR = 3;
34+ protected static final int FATAL = 4;
35+
36+ private static int logLevel= DEBUG;
37+
3038 static
3139 {
3240 try {
@@ -85,21 +93,21 @@ public class Driver implements java.sql.Driver
8593 * database.
8694 *
8795 * <p>The java.util.Properties argument can be used to pass arbitrary
88- * string tag/value pairs as connection arguments.
96+ * string tag/value pairs as connection arguments.
8997 *
9098 * user - (optional) The user to connect as
9199 * password - (optional) The password for the user
92- * charSet - (optional) The character set to be used for converting
93- * to/from the database to unicode. If multibyte is enabled on the
100+ * charSet - (optional) The character set to be used for converting
101+ * to/from the database to unicode. If multibyte is enabled on the
94102 * server then the character set of the database is used as the default,
95103 * otherwise the jvm character encoding is used as the default.
96104 * compatible - This is used to toggle
97105 * between different functionality as it changes across different releases
98- * of the jdbc driver code. The values here are versions of the jdbc
99- * client and not server versions. For example in 7.1 get/setBytes
100- * worked on LargeObject values, in 7.2 these methods were changed
101- * to work on bytea values. This change in functionality could
102- * be disabled by setting the compatible level to be "7.1", in
106+ * of the jdbc driver code. The values here are versions of the jdbc
107+ * client and not server versions. For example in 7.1 get/setBytes
108+ * worked on LargeObject values, in 7.2 these methods were changed
109+ * to work on bytea values. This change in functionality could
110+ * be disabled by setting the compatible level to be "7.1", in
103111 * which case the driver will revert to the 7.1 functionality.
104112 *
105113 * <p>Normally, at least
@@ -126,19 +134,25 @@ public class Driver implements java.sql.Driver
126134 public java.sql.Connection connect(String url, Properties info) throws SQLException
127135 {
128136 if((props = parseURL(url,info))==null)
137+ {
138+ Driver.debug("Error in url" + url);
129139 return null;
130-
140+ }
131141 try {
142+ Driver.debug("connect " + url);
143+
132144org.postgresql.Connection con = (org.postgresql.Connection)(Class.forName("@JDBCCONNECTCLASS@").newInstance());
133145con.openConnection (host(), port(), props, database(), url, this);
134146return (java.sql.Connection)con;
135147 } catch(ClassNotFoundException ex) {
148+ Driver.debug("error",ex);
136149throw new PSQLException("postgresql.jvm.version",ex);
137150 } catch(PSQLException ex1) {
138151// re-throw the exception, otherwise it will be caught next, and a
139152// org.postgresql.unusual error will be returned instead.
140153throw ex1;
141154 } catch(Exception ex2) {
155+ Driver.debug("error",ex2);
142156throw new PSQLException("postgresql.unusual",ex2);
143157 }
144158 }
@@ -392,5 +406,105 @@ public class Driver implements java.sql.Driver
392406 {
393407return new PSQLException("postgresql.unimplemented");
394408 }
409+ /**
410+ * logging message at the debug level
411+ * messages will be printed if the logging level is less or equal to DEBUG
412+ */
413+ public static void debug(String msg)
414+ {
415+ if (logLevel <= DEBUG){
416+ DriverManager.println(msg);
417+ }
418+ }
419+ /**
420+ * logging message at the debug level
421+ * messages will be printed if the logging level is less or equal to DEBUG
422+ */
423+ public static void debug(String msg, Exception ex)
424+ {
425+ if (logLevel <= DEBUG){
426+ DriverManager.println(msg + ex != null?ex.getMessage():"null Exception");
427+ }
428+ }
429+ /**
430+ * logging message at info level
431+ * messages will be printed if the logging level is less or equal to INFO
432+ */
433+ public static void info(String msg)
434+ {
435+ if (logLevel <= INFO){
436+ DriverManager.println(msg);
437+ }
438+ }
439+ /**
440+ * logging message at info level
441+ * messages will be printed if the logging level is less or equal to INFO
442+ */
443+ public static void info(String msg, Exception ex)
444+ {
445+ if (logLevel <= INFO){
446+ DriverManager.println(msg + ex != null?ex.getMessage():"null Exception");
447+ }
448+ }
449+ /**
450+ * logging message at warn level
451+ * messages will be printed if the logging level is less or equal to WARN
452+ */
453+ public static void warn(String msg)
454+ {
455+ if (logLevel <= WARN){
456+ DriverManager.println(msg);
457+ }
458+ }
459+ /**
460+ * logging message at warn level
461+ * messages will be printed if the logging level is less or equal to WARN
462+ */
463+ public static void warn(String msg, Exception ex)
464+ {
465+ if (logLevel <= WARN){
466+ DriverManager.println(msg + ex != null?ex.getMessage():"null Exception");
467+ }
468+ }
469+ /**
470+ * logging message at error level
471+ * messages will be printed if the logging level is less or equal to ERROR
472+ */
473+ public static void error(String msg)
474+ {
475+ if (logLevel <= ERROR){
476+ DriverManager.println(msg);
477+ }
478+ }
479+ /**
480+ * logging message at error level
481+ * messages will be printed if the logging level is less or equal to ERROR
482+ */
483+ public static void error(String msg, Exception ex)
484+ {
485+ if (logLevel <= ERROR){
486+ DriverManager.println(msg + ex != null?ex.getMessage():"null Exception");
487+ }
488+ }
489+ /**
490+ * logging message at fatal level
491+ * messages will be printed if the logging level is less or equal to FATAL
492+ */
493+ public static void fatal(String msg)
494+ {
495+ if (logLevel <= FATAL){
496+ DriverManager.println(msg);
497+ }
498+ }
499+ /**
500+ * logging message at fatal level
501+ * messages will be printed if the logging level is less or equal to FATAL
502+ */
503+ public static void fatal(String msg, Exception ex)
504+ {
505+ if (logLevel <= FATAL){
506+ DriverManager.println(msg + ex != null?ex.getMessage():"null Exception");
507+ }
508+ }
395509}
396510