@@ -27,6 +27,14 @@ import org.postgresql.util.PSQLException;
27
27
public class Driver implements java.sql.Driver
28
28
{
29
29
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
+
30
38
static
31
39
{
32
40
try {
@@ -85,21 +93,21 @@ public class Driver implements java.sql.Driver
85
93
* database.
86
94
*
87
95
* <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.
89
97
*
90
98
* user - (optional) The user to connect as
91
99
* 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
94
102
* server then the character set of the database is used as the default,
95
103
* otherwise the jvm character encoding is used as the default.
96
104
* compatible - This is used to toggle
97
105
* 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
103
111
* which case the driver will revert to the 7.1 functionality.
104
112
*
105
113
* <p>Normally, at least
@@ -126,19 +134,25 @@ public class Driver implements java.sql.Driver
126
134
public java.sql.Connection connect(String url, Properties info) throws SQLException
127
135
{
128
136
if((props = parseURL(url,info))==null)
137
+ {
138
+ Driver.debug("Error in url" + url);
129
139
return null;
130
-
140
+ }
131
141
try {
142
+ Driver.debug("connect " + url);
143
+
132
144
org.postgresql.Connection con = (org.postgresql.Connection)(Class.forName("@JDBCCONNECTCLASS@").newInstance());
133
145
con.openConnection (host(), port(), props, database(), url, this);
134
146
return (java.sql.Connection)con;
135
147
} catch(ClassNotFoundException ex) {
148
+ Driver.debug("error",ex);
136
149
throw new PSQLException("postgresql.jvm.version",ex);
137
150
} catch(PSQLException ex1) {
138
151
// re-throw the exception, otherwise it will be caught next, and a
139
152
// org.postgresql.unusual error will be returned instead.
140
153
throw ex1;
141
154
} catch(Exception ex2) {
155
+ Driver.debug("error",ex2);
142
156
throw new PSQLException("postgresql.unusual",ex2);
143
157
}
144
158
}
@@ -392,5 +406,105 @@ public class Driver implements java.sql.Driver
392
406
{
393
407
return new PSQLException("postgresql.unimplemented");
394
408
}
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
+ }
395
509
}
396
510
0 commit comments