Re: [BUGS]log can not be output when use DataSource

From: Dave Cramer <pg(at)fastcrypt(dot)com>
To: Chen Huajun <chenhj(at)cn(dot)fujitsu(dot)com>
Cc: dmp <danap(at)ttc-cmc(dot)net>, List <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: [BUGS]log can not be output when use DataSource
Date: 2013-01-19 11:51:06
Message-ID: CADK3HHL=XLcu3LH7CRT3c-JB8ScrBrW=O-0zDum17zrWUKKEzw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Chen,

OK, perhaps the source of the confusion is your patch.

- sb.append("&loglevel=").append(logLevel);
+ if (logLevel != 0) {
+ sb.append("&loglevel=").append(logLevel);
+ }

All this appears to do to me is: change the behaviour from always
appending the logLevel regardless of value to doing it only if it is
non-zero

Which should not change the behaviour unless the logLevel is 0 which
is the default

Dave

Dave Cramer

dave.cramer(at)credativ(dot)ca
http://www.credativ.ca

On Fri, Jan 18, 2013 at 10:33 PM, Chen Huajun <chenhj(at)cn(dot)fujitsu(dot)com> wrote:

> > Yes, it might be better, but I don't see how it fails otherwise ?
>
> Let me describe it again
> 1)Driver has a global LogLevel setting by the following
> org.postgresql.Driver.**setLogLevel()
>
> 2)each Connection has their own LogLevel,default is the same as
> Driver's,and can be rewrited by url,for example
> jdbc:postgresql://localhost/**test?loglevel=1
>
> protected AbstractJdbc2Connection(**HostSpec[] hostSpecs, String
> user, String database, Properties info, String url) throws SQLException
> {
> ...
> int logLevel = Driver.getLogLevel();
> String connectionLogLevel = info.getProperty("loglevel");
> if (connectionLogLevel != null) {
> try {
> logLevel = Integer.parseInt(**connectionLogLevel);
> } catch (Exception l_e) {
> // XXX revisit
> // invalid value for loglevel; ignore it
> }
> }
> ...
> }
>
> 3)BaseDataSource.**getConnection() will append loglevel to url regardless
> BaseDataSource.setLogLevel() was not be called
> So,the url should be as the following,and the Connection's log is off.
> jdbc:postgresql://localhost/**test?loglevel=0
>
>
> --
> Best Regards,
> Chen Huajun
>
> (2013/01/18 1:22), dmp wrote:
>
>> Also is logLevel expected in the DriverManager.getConnection(**getUrl(),
>> user, password)?
>>
>> According to the API jdbc:subprotocol:subname is expected and
>> many of the other parameters seem to not be optionally applied like
>> loginTimeout, and socketTimeout like logLevel.
>>
>> I'm also not inclinded to understand how this is a bug and fails
>> to not log, though may not report the parameter properly unless
>> the user does setLogLevel().
>>
>> danap.
>>
>>
>> Dave Cramer wrote:
>> > Yes, it might be better, but I don't see how it fails otherwise ?
>> >
>> > Dave Cramer
>> >
>> > dave.cramer(at)credativ(dot)ca
>> > http://www.credativ.ca
>> >
>> >
>> > On Thu, Jan 17, 2013 at 5:42 AM, Chen Huajun <chenhj(at)cn(dot)fujitsu(dot)com
>> > <mailto:chenhj(at)cn(dot)fujitsu(dot)com>**> wrote:
>> >
>> >
>> > > It's early here but I can't see how this makes it work. It
>> > appears that the code that is being replaced is exactly the same
>> > except that there is an if statement in front of it ?
>> > >
>> >
>> > >
>> > org.postgresql.Driver.__**setLogLevel(org.postgresql.__**
>> Driver.DEBUG);
>> >
>> > here the JVM level's LogLevel is set to be DEBUG.
>> >
>> >
>> >
>> > > DataSource source = (DataSource)new
>> > InitialContext().lookup("__**DataSource");
>> > > Connection con = source.getConnection();
>> >
>> > source.getConnection()
>> > -->DriverManager.__**getConnection(getUrl(), user, password)
>> > ->getUrl()
>> > sb.append("&loglevel=").__**append(logLevel);
>> >
>> > here the Connection's LogLevel is set to be the initial value 0(*)
>> > via URL,
>> > although nobody set DataSource's LogLevel by calling
>> > BaseDataSource.setLogLevel().
>> >
>> > I think it's better append "loglevel" to URL only when
>> > BaseDataSource.setLogLevel() was called.
>> > so a Connection created by DataSource.getConnection() can inherit
>> > JVM level's LogLevel setting
>> > just like which one created by DriverManager.getConnection().
>> >
>> >
>> > *)0 is the initial value and not a valid LogLevel,
>> > valid values are INFO (1) and DEBUG (2).
>> >
>> >
>> > --
>> > Best Regards,
>> > Chen Huajun
>> > (2013/01/17 17:19), Dave Cramer wrote:
>> >
>> > It's early here but I can't see how this makes it work. It
>> > appears that the code that is being replaced is exactly the same
>> > except that there is an if statement in front of it ?
>> >
>> >
>> >
>> > Dave Cramer
>> >
>> > dave.cramer(at)credativ(dot)ca
>> > http://www.credativ.ca
>> >
>> >
>> > On Wed, Jan 16, 2013 at 11:47 PM, Chen Huajun
>> > <chenhj(at)cn(dot)fujitsu(dot)com <mailto:chenhj(at)cn(dot)fujitsu(dot)com>
>> > <mailto:chenhj(at)cn(dot)fujitsu(dot)com <mailto:chenhj(at)cn(dot)fujitsu(dot)com>**>__>
>> > wrote:
>> >
>> > Hi,
>> >
>> > In the following code,log can not be output as expected.
>> >
>> > ------------------------------**__-------
>> >
>> > org.postgresql.Driver.__**setLogLevel(org.postgresql.__**
>> Driver.DEBUG);
>> > DataSource source = (DataSource)new
>> > InitialContext().lookup("__**DataSource");
>> > Connection con = source.getConnection();
>> > ------------------------------**__-------
>> >
>> > It's seems to be a problem,
>> > I have made a small patch to fix it.
>> > Hopefully this useful.
>> >
>> > --
>> > Best Regards,
>> > Chen Huajun
>> > --
>> > Sent via pgsql-jdbc mailing list (pgsql-jdbc(at)postgresql(dot)org
>> > <mailto:pgsql-jdbc(at)postgresql(dot)**org <pgsql-jdbc(at)postgresql(dot)org>>
>> > <mailto:pgsql-jdbc(at)postgresql(dot)**__org
>> > <mailto:pgsql-jdbc(at)postgresql(dot)**org <pgsql-jdbc(at)postgresql(dot)org>>>)
>> >
>> > To make changes to your subscription:
>> > http://www.postgresql.org/__**mailpref/pgsql-jdbc<http://www.postgresql.org/__mailpref/pgsql-jdbc>
>> > <http://www.postgresql.org/**mailpref/pgsql-jdbc<http://www.postgresql.org/mailpref/pgsql-jdbc>
>> >
>>
>>
>>
>
>
>
>
>
> --
> Sent via pgsql-jdbc mailing list (pgsql-jdbc(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/**mailpref/pgsql-jdbc<http://www.postgresql.org/mailpref/pgsql-jdbc>
>

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message dmp 2013-01-19 19:52:42 Re: [BUGS]log can not be output when use DataSource
Previous Message Chen Huajun 2013-01-19 03:33:23 Re: [BUGS]log can not be output when use DataSource