Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TxFH7-0007Yd-QV for pgsql-jdbc@arkaria.postgresql.org; Mon, 21 Jan 2013 11:10:50 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1TxFH7-0002ZX-Bb for pgsql-jdbc@arkaria.postgresql.org; Mon, 21 Jan 2013 11:10:49 +0000 Received: from magus.postgresql.org ([87.238.57.229]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TxFH6-0002ZS-ML for pgsql-jdbc@postgresql.org; Mon, 21 Jan 2013 11:10:48 +0000 Received: from [222.73.24.84] (helo=song.cn.fujitsu.com) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TxFH2-0005lG-SR for pgsql-jdbc@postgresql.org; Mon, 21 Jan 2013 11:10:48 +0000 X-IronPort-AV: E=Sophos;i="4.84,506,1355068800"; d="scan'208";a="6622297" Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 21 Jan 2013 19:08:32 +0800 Received: from fnstmail02.fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id r0LAR1JJ031379; Mon, 21 Jan 2013 18:27:01 +0800 Received: from [127.0.0.1] ([10.167.159.99]) by fnstmail02.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.3) with ESMTP id 2013012118260893-1061979 ; Mon, 21 Jan 2013 18:26:08 +0800 Message-ID: <50FD1818.8060002@cn.fujitsu.com> Date: Mon, 21 Jan 2013 18:27:36 +0800 From: Chen Huajun User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; ja; rv:1.9.2.28) Gecko/20120306 Lightning/1.0b2 Thunderbird/3.1.20 MIME-Version: 1.0 To: dmp CC: pgsql-jdbc@postgresql.org Subject: Re: [BUGS]log can not be output when use DataSource References: <50F8335B.6070404@ttc-cmc.net> <50FA1403.7020301@cn.fujitsu.com> <50FAF98A.1030008@ttc-cmc.net> <50FBCA78.3040007@cn.fujitsu.com> <50FC3529.3060101@ttc-cmc.net> <50FCC7EC.7050307@cn.fujitsu.com> In-Reply-To: <50FCC7EC.7050307@cn.fujitsu.com> X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/01/21 18:26:08, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/01/21 18:26:10 Content-Type: multipart/mixed; boundary="------------010904010004030805070700" X-Host-Lookup-Failed: Reverse DNS lookup failed for 222.73.24.84 (failed) X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org --------------010904010004030805070700 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=UTF-8; format=flowed Hi > > > If you would create sample code to run to validate both your > > bug report and test your patch you may have seen the breakage. > > I can tell you that in all cases when DataSource.SetLogLevel(0) > > your patch breaks the standard of the user overrides the > > Driver.setLogLevel() when it is stipulated. > > > > I know that valid inputs maybe only be Driver.INFO & Driver.DEBUG, > > but if you treat the PgJDBC has a black box which you stimulate > > and watch the output then we can not ignore the boundard cases of > > <0, 0, & >2. > I made a new patch to avoid the above problem. But i found a new another problem. In the following code,source2.getConnection() fail to output log as expected. ---------------------------------------- PGPoolingDataSourcesource = new PGPoolingDataSource(); source.setLogLevel(2); Connection con = source.getConnection();//OK, log does output Properties props = new Properties(); props.put(InitialContext.INITIAL_CONTEXT_FACTORY, "org.postgresql.test.util.MiniJndiContextFactory"); InitialContext initialContext = new InitialContext(props); initialContext.rebind("DataSource", source); BaseDataSource source2 = (BaseDataSource) initialContext.lookup("DataSource"); con = source2.getConnection();//NG, log does not output ---------------------------------------- The reason is that loadBaseDataSource(BaseDataSource ds, Reference ref) fail to copy all properties from ref when source2 was created. So the loglevel of source2 remains to be the defualt value 0. Not only loglevel, some other properties such as "ssl" have the same problem. Chen Huajun --------------010904010004030805070700 Content-Type: text/plain; name="pgjdbc_loglevel_v2.patch" Content-Disposition: attachment; filename="pgjdbc_loglevel_v2.patch" Content-Transfer-Encoding: quoted-printable diff --git a/org/postgresql/ds/common/BaseDataSource.java b/org/postgresql/= ds/common/BaseDataSource.java index bfe54f7..2aa7b31 100644 --- a/org/postgresql/ds/common/BaseDataSource.java +++ b/org/postgresql/ds/common/BaseDataSource.java @@ -63,6 +63,7 @@ private int logLevel =3D 0; private int protocolVersion =3D 0; private String applicationName; + private boolean logLevelIsSet =3D false; =20 /** * Gets a connection to the PostgreSQL database. The database is iden= tified by the @@ -184,6 +185,7 @@ public void setLogLevel(int logLevel) { this.logLevel =3D logLevel; + logLevelIsSet =3D true; } =20 public int getProtocolVersion() @@ -486,7 +488,9 @@ sb.append("&socketTimeout=3D").append(socketTimeout); sb.append("&prepareThreshold=3D").append(prepareThreshold); sb.append("&unknownLength=3D").append(unknownLength); - sb.append("&loglevel=3D").append(logLevel); + if (logLevelIsSet) { + sb.append("&loglevel=3D").append(logLevel); + } if (protocolVersion !=3D 0) { sb.append("&protocolVersion=3D").append(protocolVersion); } @@ -562,7 +566,10 @@ ref.add(new StringRefAddr("compatible", compatible)); } =20 - ref.add(new StringRefAddr("logLevel", Integer.toString(logLevel))); + if(logLevelIsSet) + { + ref.add(new StringRefAddr("logLevel", Integer.toString(logLeve= l))); + } ref.add(new StringRefAddr("protocolVersion", Integer.toString(prot= ocolVersion))); ref.add(new StringRefAddr("ApplicationName", applicationName)); =20 @@ -592,6 +599,7 @@ out.writeBoolean(binaryTransfer); out.writeObject(binaryTransferEnable); out.writeObject(binaryTransferDisable); + out.writeBoolean(logLevelIsSet); } =20 protected void readBaseObject(ObjectInputStream in) throws IOException= , ClassNotFoundException @@ -617,6 +625,7 @@ binaryTransfer =3D in.readBoolean(); binaryTransferEnable =3D (String)in.readObject(); binaryTransferDisable =3D (String)in.readObject(); + logLevelIsSet =3D in.readBoolean(); } =20 public void initializeFrom(BaseDataSource source) throws IOException, = ClassNotFoundException {= --------------010904010004030805070700 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-jdbc --------------010904010004030805070700--