You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If user didn't configure any logging, the exception instance is printed to stderr
Exception in thread "main" java.lang.RuntimeException: test exception
at com.test.App.main(App.java:40)
If user set LOG_LEVEL or configured logback/etc, we get a log in stdout and uncaught exception in stderr
2025-04-02 14:42:16.032 [main] [ERROR] com.test.App - {"exception.type":"java.lang.RuntimeException","exception.message":"test exception","hello":"world"}
Exception in thread "main" java.lang.RuntimeException: test exception
at com.test.App.main(App.java:13)
Assuming user didn't enable our logging and sees unhandled exception or logs it on their own, they don't get any context provided to the log record.
With exceptions, we want to make sure we put all the important details into the exception instance (message), not just on the log record.
I.e. we should do something like
StringerrorMessage = String.format("Connection with id '%d' terminated, reason - '%s'", connectionId, reason);
throwlogger.logThrowableAsError(newSomeException(errorMessage));
which in its turn becomes more friendly to users who don't use logging and less friendly to those who do (since we no longer provide structured context)).
But then it's not friendly to anyone who needs to write it - it's also hard to keep exception message and log consistent.
We should consider providing a convenience for lib developers to simplify exception creation along with logging it.
We can consider producing an exception message like Connection terminated. {"connectionId": "...", "reason" : "..."} while the log record full be fully structured.
The text was updated successfully, but these errors were encountered:
Here's what happens when we're doing something like
LOG_LEVEL
or configured logback/etc, we get a log in stdout and uncaught exception in stderrAssuming user didn't enable our logging and sees unhandled exception or logs it on their own, they don't get any context provided to the log record.
With exceptions, we want to make sure we put all the important details into the exception instance (message), not just on the log record.
I.e. we should do something like
which in its turn becomes more friendly to users who don't use logging and less friendly to those who do (since we no longer provide structured context)).
To make it friendly to all users, we could do
But then it's not friendly to anyone who needs to write it - it's also hard to keep exception message and log consistent.
We should consider providing a convenience for lib developers to simplify exception creation along with logging it.
We can consider producing an exception message like
Connection terminated. {"connectionId": "...", "reason" : "..."}
while the log record full be fully structured.The text was updated successfully, but these errors were encountered: