Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb465f53

Browse files
author
Barry Lind
committed
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 numberAdds member variables logDebug and logInfo that can be checked before making logging methods callsAdds 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----------------------------------------------------------------------
1 parent8d1c1d4 commitb465f53

File tree

8 files changed

+1378
-1412
lines changed

8 files changed

+1378
-1412
lines changed

‎src/interfaces/jdbc/org/postgresql/Connection.java

Lines changed: 1246 additions & 1215 deletions
Large diffs are not rendered by default.

‎src/interfaces/jdbc/org/postgresql/Driver.java.in

Lines changed: 25 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,10 @@ public class Driver implements java.sql.Driver
2929

3030
// make these public so they can be used in setLogLevel below
3131

32-
public static final int DEBUG =0;
32+
public static final int DEBUG =2;
3333
public static final int INFO = 1;
34-
public static final int WARN = 2;
35-
public static final int ERROR = 3;
36-
public static final int FATAL = 4;
37-
38-
private static int logLevel = FATAL;
34+
public static boolean logDebug = false;
35+
public static boolean logInfo = false;
3936

4037
static
4138
{
@@ -46,7 +43,6 @@ public class Driver implements java.sql.Driver
4643
// my early jdbc work did - and that was based on other examples).
4744
// Placing it here, means that the driver is registered once only.
4845
java.sql.DriverManager.registerDriver(new Driver());
49-
5046
}
5147
catch (SQLException e)
5248
{
@@ -106,7 +102,12 @@ public class Driver implements java.sql.Driver
106102
* to/from the database to unicode. If multibyte is enabled on the
107103
* server then the character set of the database is used as the default,
108104
* otherwise the jvm character encoding is used as the default.
109-
* compatible - This is used to toggle
105+
* loglevel - (optional) Enable logging of messages from the driver.
106+
* The value is an integer from 1 to 2 where:
107+
* INFO = 1, DEBUG = 2
108+
* The output is sent to DriverManager.getPrintWriter() if set,
109+
* otherwise it is sent to System.out.
110+
* compatible - (optional) This is used to toggle
110111
* between different functionality as it changes across different releases
111112
* of the jdbc driver code. The values here are versions of the jdbc
112113
* client and not server versions. For example in 7.1 get/setBytes
@@ -140,20 +141,20 @@ public class Driver implements java.sql.Driver
140141
{
141142
if ((props = parseURL(url, info)) == null)
142143
{
143-
Driver.debug("Error in url" + url);
144+
if (Driver.logDebug)Driver.debug("Error in url" + url);
144145
return null;
145146
}
146147
try
147148
{
148-
Driver.debug("connect " + url);
149+
if (Driver.logDebug)Driver.debug("connect " + url);
149150

150151
org.postgresql.Connection con = (org.postgresql.Connection)(Class.forName("@JDBCCONNECTCLASS@").newInstance());
151152
con.openConnection (host(), port(), props, database(), url, this);
152153
return (java.sql.Connection)con;
153154
}
154155
catch (ClassNotFoundException ex)
155156
{
156-
Driver.debug("error", ex);
157+
if (Driver.logDebug)Driver.debug("error", ex);
157158
throw new PSQLException("postgresql.jvm.version", ex);
158159
}
159160
catch (PSQLException ex1)
@@ -164,7 +165,7 @@ public class Driver implements java.sql.Driver
164165
}
165166
catch (Exception ex2)
166167
{
167-
Driver.debug("error", ex2);
168+
if (Driver.logDebug)Driver.debug("error", ex2);
168169
throw new PSQLException("postgresql.unusual", ex2);
169170
}
170171
}
@@ -251,7 +252,7 @@ public class Driver implements java.sql.Driver
251252
*/
252253
public static String getVersion()
253254
{
254-
return "@VERSION@";
255+
return "@VERSION@ jdbc driver build " + m_buildNumber;
255256
}
256257

257258
/*
@@ -293,12 +294,6 @@ public class Driver implements java.sql.Driver
293294
{
294295
String token = st.nextToken();
295296

296-
// PM June 29 1997
297-
// Added this, to help me understand how this works.
298-
// Unless you want each token to be processed, leave this commented out
299-
// but don't delete it.
300-
//DriverManager.println("wellFormedURL: state="+state+" count="+count+" token='"+token+"'");
301-
302297
// PM Aug 2 1997 - Modified to allow multiple backends
303298
if (count <= 3)
304299
{
@@ -379,21 +374,13 @@ public class Driver implements java.sql.Driver
379374
else if (state == -5)
380375
{
381376
value = token;
382-
//DriverManager.println("put("+key+","+value+")");
383377
urlProps.put(key, value);
384378
state = -2;
385379
}
386380
}
387381
}
388382
}
389383

390-
// PM June 29 1997
391-
// This now outputs the properties only if we are logging
392-
// PM Sep 13 1999 Commented out, as it throws a Deprecation warning
393-
// when compiled under JDK1.2.
394-
//if (DriverManager.getLogStream() != null)
395-
//urlProps.list(DriverManager.getLogStream());
396-
397384
return urlProps;
398385

399386
}
@@ -446,20 +433,21 @@ public class Driver implements java.sql.Driver
446433
*used to turn logging on to a certain level, can be called
447434
*by specifying fully qualified class ie org.postgresql.Driver.setLogLevel()
448435
*@param int logLevel sets the level which logging will respond to
449-
*FATAL being almost no messages
436+
*INFO being almost no messages
450437
*DEBUG most verbose
451438
*/
452439
public static void setLogLevel(int logLevel)
453440
{
454-
Driver.logLevel = logLevel;
441+
logDebug = (logLevel >= DEBUG) ? true : false;
442+
logInfo = (logLevel >= INFO) ? true : false;
455443
}
456444
/*
457445
* logging message at the debug level
458446
* messages will be printed if the logging level is less or equal to DEBUG
459447
*/
460448
public static void debug(String msg)
461449
{
462-
if (logLevel <= DEBUG)
450+
if (logDebug)
463451
{
464452
DriverManager.println(msg);
465453
}
@@ -470,7 +458,7 @@ public class Driver implements java.sql.Driver
470458
*/
471459
public static void debug(String msg, Exception ex)
472460
{
473-
if (logLevel <= DEBUG)
461+
if (logDebug)
474462
{
475463
DriverManager.println(msg + ex != null ? ex.getMessage() : "null Exception");
476464
}
@@ -481,7 +469,7 @@ public class Driver implements java.sql.Driver
481469
*/
482470
public static void info(String msg)
483471
{
484-
if (logLevel <= INFO)
472+
if (logInfo)
485473
{
486474
DriverManager.println(msg);
487475
}
@@ -492,75 +480,13 @@ public class Driver implements java.sql.Driver
492480
*/
493481
public static void info(String msg, Exception ex)
494482
{
495-
if (logLevel <= INFO)
496-
{
497-
DriverManager.println(msg + ex != null ? ex.getMessage() : "null Exception");
498-
}
499-
}
500-
/*
501-
* logging message at warn level
502-
* messages will be printed if the logging level is less or equal to WARN
503-
*/
504-
public static void warn(String msg)
505-
{
506-
if (logLevel <= WARN)
507-
{
508-
DriverManager.println(msg);
509-
}
510-
}
511-
/*
512-
* logging message at warn level
513-
* messages will be printed if the logging level is less or equal to WARN
514-
*/
515-
public static void warn(String msg, Exception ex)
516-
{
517-
if (logLevel <= WARN)
518-
{
519-
DriverManager.println(msg + ex != null ? ex.getMessage() : "null Exception");
520-
}
521-
}
522-
/*
523-
* logging message at error level
524-
* messages will be printed if the logging level is less or equal to ERROR
525-
*/
526-
public static void error(String msg)
527-
{
528-
if (logLevel <= ERROR)
529-
{
530-
DriverManager.println(msg);
531-
}
532-
}
533-
/*
534-
* logging message at error level
535-
* messages will be printed if the logging level is less or equal to ERROR
536-
*/
537-
public static void error(String msg, Exception ex)
538-
{
539-
if (logLevel <= ERROR)
540-
{
541-
DriverManager.println(msg + ex != null ? ex.getMessage() : "null Exception");
542-
}
543-
}
544-
/*
545-
* logging message at fatal level
546-
* messages will be printed if the logging level is less or equal to FATAL
547-
*/
548-
public static void fatal(String msg)
549-
{
550-
if (logLevel <= FATAL)
551-
{
552-
DriverManager.println(msg);
553-
}
554-
}
555-
/*
556-
* logging message at fatal level
557-
* messages will be printed if the logging level is less or equal to FATAL
558-
*/
559-
public static void fatal(String msg, Exception ex)
560-
{
561-
if (logLevel <= FATAL)
483+
if (logInfo)
562484
{
563485
DriverManager.println(msg + ex != null ? ex.getMessage() : "null Exception");
564486
}
565487
}
488+
489+
//The build number should be incremented for every new build
490+
private static int m_buildNumber = 100;
491+
566492
}

‎src/interfaces/jdbc/org/postgresql/fastpath/Fastpath.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
packageorg.postgresql.fastpath;
22

3+
importorg.postgresql.Driver;
34
importjava.io.*;
45
importjava.lang.*;
56
importjava.net.*;
@@ -44,7 +45,6 @@ public Fastpath(org.postgresql.Connection conn, org.postgresql.PG_Stream stream)
4445
{
4546
this.conn =conn;
4647
this.stream =stream;
47-
//DriverManager.println("Fastpath initialised");
4848
}
4949

5050
/*
@@ -174,7 +174,7 @@ public Object fastpath(int fnid, boolean resulttype, FastpathArg[] args) throws
174174
*/
175175
publicObjectfastpath(Stringname,booleanresulttype,FastpathArg[]args)throwsSQLException
176176
{
177-
//DriverManager.println("Fastpath: calling "+name);
177+
if (Driver.logDebug)Driver.debug("Fastpath: calling "+name);
178178
returnfastpath(getID(name),resulttype,args);
179179
}
180180

‎src/interfaces/jdbc/org/postgresql/jdbc1/DatabaseMetaData.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
/*
1414
* This class provides information about the database as a whole.
1515
*
16-
* $Id: DatabaseMetaData.java,v 1.45 2002/06/06 14:47:52 davec Exp $
16+
* $Id: DatabaseMetaData.java,v 1.46 2002/06/11 02:55:16 barry Exp $
1717
*
1818
* <p>Many of the methods here return lists of information in ResultSets. You
1919
* can use the normal ResultSet methods such as getString and getInt to
@@ -1731,7 +1731,7 @@ public java.sql.ResultSet getTables(String catalog, String schemaPattern, String
17311731
StringrelKind;
17321732
switch (r.getBytes(3)[0])
17331733
{
1734-
case (byte)'r':
1734+
case (byte)'r':
17351735
if (r.getString(1).startsWith("pg_") )
17361736
{
17371737
relKind ="SYSTEM TABLE";
@@ -2108,7 +2108,6 @@ public java.sql.ResultSet getColumnPrivileges(String catalog, String schema, Str
21082108
{
21092109
byte[][]tuple =newbyte[8][0];
21102110
tuple[0] =tuple[1] ="".getBytes();
2111-
DriverManager.println("relname=\"" +r.getString(1) +"\" relacl=\"" +r.getString(2) +"\"");
21122111

21132112
// For now, don't add to the result as relacl needs to be processed.
21142113
//v.addElement(tuple);

‎src/interfaces/jdbc/org/postgresql/jdbc2/Connection.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
importorg.postgresql.util.*;
1818

1919
/*
20-
* $Id: Connection.java,v 1.18 2002/03/26 05:52:50 barry Exp $
20+
* $Id: Connection.java,v 1.19 2002/06/11 02:55:16 barry Exp $
2121
*
2222
* A Connection represents a session with a specific database.Within the
2323
* context of a Connection, SQL statements are executed and results are
@@ -318,6 +318,14 @@ public int getSQLType(String pgTypeName)
318318
Types.ARRAY
319319
};
320320

321+
//Because the get/setLogStream methods are deprecated in JDBC2
322+
//we use the get/setLogWriter methods here for JDBC2 by overriding
323+
//the base version of this method
324+
protectedvoidenableDriverManagerLogging() {
325+
if (DriverManager.getLogWriter() ==null) {
326+
DriverManager.setLogWriter(newPrintWriter(System.out));
327+
}
328+
}
321329

322330
}
323331

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp