Skip to content

Conversation

abstractdog
Copy link
Contributor

What changes were proposed in this pull request?

Why are the changes needed?

Does this PR introduce any user-facing change?

How was this patch tested?

Copy link

sonarqubecloud bot commented Sep 1, 2025

@abstractdog abstractdog changed the title HIVE-29173: Replace string concatenation in log messages with logging format [DRAFT] HIVE-29173: Replace string concatenation in log messages with logging format Sep 2, 2025
@abstractdog abstractdog marked this pull request as draft September 2, 2025 07:45
Copy link
Member

@zabetak zabetak left a comment

Choose a reason for hiding this comment

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

The main concern is the logging that involves exceptions. In most cases the number of placeholders is different from the number of arguments so I am wondering if we get the expected output. Is the exception, which usually appears at the end, logged correctly?

// instead.
LOG.error("getting attribute " + prs + " of " + oname
+ " threw an exception", e);
LOG.error("getting attribute {} of {} threw an exception", prs, oname, e);
Copy link
Member

Choose a reason for hiding this comment

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

I am wondering if the exception serialization remains the same after this change since we no longer use the API that accepts a Throwable.

Copy link
Member

Choose a reason for hiding this comment

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

In addition it is strange that we use two placeholders {} but we pass three arguments.

return metaClients().run(client -> client.getTable(database(), table()));
} catch (NoSuchObjectException nte) {
LOG.trace("Table not found {}", database() + "." + table(), nte);
LOG.trace("Table not found {}.{}", database(), table(), nte);
Copy link
Member

Choose a reason for hiding this comment

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

Two placeholders but three arguments.

if (!tok.getService().equals(service)) {
LOG.debug("Not importing credentials for service " + service +
"(expecting service " + service + ")");
LOG.debug("Not importing credentials for service {} (expecting service {})", service, service);
Copy link
Member

Choose a reason for hiding this comment

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

Passing the same object two times does not make much sense but I guess outside the scope of the PR.

din.close();
} catch (Exception err) {
LOG.error("Error closing input stream:" + err.getMessage(), err);
LOG.error("Error closing input stream: {}", err.getMessage(), err);
Copy link
Member

Choose a reason for hiding this comment

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

How about something simpler:

LOG.error("Error closing input stream:", err);

}
} catch (UnknownHostException e) {
LOG.warn("Ignoring resolution issues for host: " + host, e);
LOG.warn("Ignoring resolution issues for host: {}", host, e);
Copy link
Member

Choose a reason for hiding this comment

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

One placeholder, two arguments.

} catch (Exception e) {
LOG.warn("Failed to cleanup root dir of HS2 logging: " + operationLogRootDir
.getAbsolutePath(), e);
LOG.warn("Failed to cleanup root dir of HS2 logging: {}", operationLogRootDir.getAbsolutePath(), e);
Copy link
Member

Choose a reason for hiding this comment

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

placeholders~=args

LOG.info("This instance of HiveServer2 has been removed from the list of server "
+ "instances available for dynamic service discovery. "
+ "The last client session has ended - will shutdown now.");
LOG.info("This instance of HiveServer2 has been removed from the list of server "
Copy link
Member

Choose a reason for hiding this comment

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

wrong indent

LOG.warn(
"Unable to inherit permissions for file " + target + " from file " + sourceStatus.getFileStatus().getPath(),
e.getMessage());
LOG.warn("Unable to inherit permissions for file {} from file {}",
Copy link
Member

Choose a reason for hiding this comment

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

placeholders~=args

LOG.debug("The details are: " + e, e);
LOG.info("Skipping ACL inheritance: File system for path {} does not support ACLs " +
"but dfs.namenode.acls.enabled is set to true.", file);
LOG.debug("The details are: {}", e);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
LOG.debug("The details are: {}", e);
LOG.debug("The details are:", e);

LOG.debug("The details are: " + e, e);
LOG.info("Skipping ACL inheritance: File system for path {} does not support ACLs " +
"but dfs.namenode.acls.enabled is set to true.", target);
LOG.debug("The details are: {}", e);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
LOG.debug("The details are: {}", e);
LOG.debug("The details are:", e);

@abstractdog
Copy link
Contributor Author

@zabetak : in general, with SLF4J, the last argument is always treated in a special way, which can be a throwable, and doesn't have to be added to the logging format
https://www.slf4j.org/faq.html#paramException

btw, this PR is getting bigger and bigger, that's why I set this to draft, not sure where it ends :D
thanks for taking a look so far!

@InvisibleProgrammer
Copy link
Contributor

It looks like a tiring and boring manual work. What about giving a shot to an automatized solution, like OpenRewrite?
See: https://docs.openrewrite.org/recipes/java/logging/parameterizedlogging

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants