Skip to content

Commit

Permalink
ZOOKEEPER-4515: ZK Cli quit command always logs error
Browse files Browse the repository at this point in the history
1. For connection closing state scenario, changed the log level to debug
2. When JVM exiting with code 0, then logging info instead of error

Author: Mohammad Arshad <arshad@apache.org>

Reviewers: tison <wander4096@gmail.com>, Enrico Olivelli <eolivelli@apache.org>

Closes apache#1856 from arshadmohammad/ZOOKEEPER-4515-cli and squashes the following commits:

e7e248b [Mohammad Arshad] Logging error only when exit code is non zero
31e124a [Mohammad Arshad] ZOOKEEPER-4515: ZK Cli quit command always logs error 1. For connection closing state scenario, changed the log level to debug 2. When JVM exiting with code 0, then logging info instead of error
  • Loading branch information
arshadmohammad authored and anurag-harness committed Jan 13, 2023
1 parent 3b5b7b2 commit 11dae71
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1284,10 +1284,11 @@ public void run() {
} catch (Throwable e) {
if (closing) {
// closing so this is expected
LOG.warn(
"An exception was thrown while closing send thread for session 0x{}.",
Long.toHexString(getSessionId()),
e);
if (LOG.isDebugEnabled()) {
LOG.debug(
"An exception was thrown while closing send thread for session 0x{}.",
Long.toHexString(getSessionId()), e);
}
break;
} else {
LOG.warn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,27 @@ private ServiceUtils() {
*/
@SuppressFBWarnings("DM_EXIT")
public static final Consumer<Integer> SYSTEM_EXIT = (code) -> {
LOG.error("Exiting JVM with code {}", code);
String msg = "Exiting JVM with code {}";
if (code == 0) {
// JVM exits normally
LOG.info(msg, code);
} else {
// JVM exits with error
LOG.error(msg, code);
}
System.exit(code);
};

/**
* No-op strategy, useful for tests.
*/
public static final Consumer<Integer> LOG_ONLY = (code) -> {
LOG.error("Fatal error, JVM should exit with code {}. "
if (code != 0) {
LOG.error("Fatal error, JVM should exit with code {}. "
+ "Actually System.exit is disabled", code);
} else {
LOG.info("JVM should exit with code {}. Actually System.exit is disabled", code);
}
};

private static volatile Consumer<Integer> systemExitProcedure = SYSTEM_EXIT;
Expand Down

0 comments on commit 11dae71

Please sign in to comment.