Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: logger should be generally quiet #1187

Merged
merged 1 commit into from
Jul 1, 2018
Merged

Conversation

jorsol
Copy link
Member

@jorsol jorsol commented May 10, 2018

The logger used in the driver has some calls to levels WARNING and SEVERE, this lower the level to FINE to make the logger quiet.

Changing SEVERE to WARNING is not enough, as WARNING is higher than INFO the default global logging level.

fixes #1009
fixes #1162
closes #1149

@codecov-io
Copy link

codecov-io commented May 10, 2018

Codecov Report

Merging #1187 into master will increase coverage by 0.04%.
The diff coverage is 65%.

@@             Coverage Diff              @@
##             master    #1187      +/-   ##
============================================
+ Coverage     68.63%   68.67%   +0.04%     
- Complexity     3830     3833       +3     
============================================
  Files           173      173              
  Lines         15997    15996       -1     
  Branches       2609     2609              
============================================
+ Hits          10979    10986       +7     
+ Misses         3784     3778       -6     
+ Partials       1234     1232       -2

Copy link
Member

@vlsi vlsi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with some of the changes, however I think other lines should not be changed

@@ -125,7 +125,7 @@ private Properties loadDefaultProperties() throws IOException {
}

if (cl == null) {
LOGGER.log(Level.WARNING, "Can't find a classloader for the Driver; not loading driver configuration");
LOGGER.log(Level.FINE, "Can't find a classloader for the Driver; not loading driver configuration");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 regarding this case.
On top of that, it makes sense to add a word on org/postgresql/driverconfig.properties so it is clear which configuration was skipped.

@@ -232,7 +232,7 @@ public Connection connect(String url, Properties info) throws SQLException {
}
// parse URL and add more properties
if ((props = parseURL(url, props)) == null) {
LOGGER.log(Level.SEVERE, "Error in url: {0}", url);
LOGGER.log(Level.FINE, "Error in url: {0}", url);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TL;DR: -1 for the change.
Am I missing a case?

I think this warning could never appear in properly configured setup, so I think this logging should be enabled by default, so it highlights errors in configuration.

Looking a bit more, I think it could make logging more detailed (e.g. move it inside parseURL, so error messages are more focused).

@@ -260,7 +260,7 @@ public Connection connect(String url, Properties info) throws SQLException {
thread.start();
return ct.getResult(timeout);
} catch (PSQLException ex1) {
LOGGER.log(Level.SEVERE, "Connection error: ", ex1);
LOGGER.log(Level.FINE, "Connection error: ", ex1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 The error is re-thrown, so logging level could be reduced.

@@ -270,7 +270,7 @@ public Connection connect(String url, Properties info) throws SQLException {
"Your security policy has prevented the connection from being attempted. You probably need to grant the connect java.net.SocketPermission to the database server host and port that you wish to connect to."),
PSQLState.UNEXPECTED_ERROR, ace);
} catch (Exception ex2) {
LOGGER.log(Level.SEVERE, "Unexpected connection error: ", ex2);
LOGGER.log(Level.FINE, "Unexpected connection error: ", ex2);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@@ -659,7 +659,7 @@ private static long timeout(Properties props) {
try {
return (long) (Float.parseFloat(timeout) * 1000);
} catch (NumberFormatException e) {
LOGGER.log(Level.WARNING, "Couldn't parse loginTimeout value: {0}", timeout);
LOGGER.log(Level.FINE, "Couldn't parse loginTimeout value: {0}", timeout);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-1 as this happens in case user provides loginTimeout property and it gets ignored.
Does that really happen often?
I think this log message would appear just in case one tries to put invalid value, and it would warn that the value is ignored.

@@ -97,7 +97,7 @@ public Connection getConnection(String user, String password) throws SQLExceptio
}
return con;
} catch (SQLException e) {
LOGGER.log(Level.SEVERE, "Failed to create a {0} for {1} at {2}: {3}",
LOGGER.log(Level.FINE, "Failed to create a {0} for {1} at {2}: {3}",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@@ -1369,7 +1369,7 @@ public boolean isValid(int timeout) throws SQLException {
// "current transaction aborted", assume the connection is up and running
return true;
}
LOGGER.log(Level.WARNING, GT.tr("Validating connection."), e);
LOGGER.log(Level.FINE, GT.tr("Validating connection."), e);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-1 The exception is not re-thrown, so hiding it by default might make "root cause analysis" harder.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the exception is not re-thrown but the method returns a boolean indicating if the connection is Valid, the point of the method is not get the "root cause", is to validate the connection.

For instance if a connection pool every time it tries to borrow a connection check if is valid, this will flood the log for no reason.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@@ -88,17 +88,17 @@ public boolean isSSPISupported() {
* won't have JNA and this will throw a NoClassDefFoundError.
*/
if (!Platform.isWindows()) {
LOGGER.log(Level.WARNING, "SSPI not supported: non-Windows host");
LOGGER.log(Level.FINE, "SSPI not supported: non-Windows host");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

return false;
}
/* Waffle must be on the CLASSPATH */
Class.forName("waffle.windows.auth.impl.WindowsSecurityContextImpl");
return true;
} catch (NoClassDefFoundError ex) {
LOGGER.log(Level.WARNING, "SSPI unavailable (no Waffle/JNA libraries?)", ex);
LOGGER.log(Level.FINE, "SSPI unavailable (no Waffle/JNA libraries?)", ex);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-1 as it might highlight configuration issues.
On the other hand, it could make sense to make this one-time-only log message (e.g. static boolean sspiUnavailable in SSPIClient class

@@ -63,7 +63,7 @@ public synchronized void releaseTimer() {
}
} else {
// Should not get here under normal circumstance, probably a bug in app code.
LOGGER.log(Level.WARNING,
LOGGER.log(Level.FINE,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-1 as this should never happen, and the message highlights something fishy

@jorsol jorsol force-pushed the remove-log-ex branch 3 times, most recently from 84e7204 to 823d3ed Compare May 21, 2018 20:05
@vlsi
Copy link
Member

vlsi commented Jun 30, 2018

@jorsol , would you please rebase and add a CHANGELOG.md entry?

@vlsi vlsi added this to the 42.2.3 milestone Jun 30, 2018
@jorsol
Copy link
Member Author

jorsol commented Jul 1, 2018

Rebased and CHANGELOG.md entry added.

@@ -178,23 +172,18 @@ public QueryExecutor openConnectionImpl(HostSpec[] hostSpecs, String user, Strin

// Set SO_RECVBUF read buffer size
int receiveBufferSize = PGProperty.RECEIVE_BUFFER_SIZE.getInt(info);
if (receiveBufferSize > -1) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK -1 was here to just use system default. Raising a warning for that case is not good

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was that an intentional change?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted.

The logger used in the driver has some calls to levels WARNING and SEVERE
this lower the level to FINE to make the logger quiet in some cases.
@vlsi vlsi merged commit 30f06e1 into pgjdbc:master Jul 1, 2018
@bokken bokken mentioned this pull request Jul 3, 2018
@jorsol jorsol deleted the remove-log-ex branch May 15, 2019 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can the log message be made silent. Why is Driver class logging connection errors?
3 participants