qos-ch / slf4j

Simple Logging Facade for Java
http://www.slf4j.org
MIT License
2.32k stars 980 forks source link

[Feature Request]: Add error method with varargs and Throwable in Logger interface #400

Open ThinkPeace opened 6 months ago

ThinkPeace commented 6 months ago

Feature request I am requesting a feature where the logger interface is extended to have an error method that accepts varargs along with a Throwable.

Motivation Currently, the error method accepts either a message with varargs or a message with a Throwable. There isn't a method that accepts both combined. This leads to a situation where developers are forced to combine messages and/or params with error objects manually, which can lead to loss of stack trace information or awkward workarounds.

Suggested Solution Add the following method to the Logger interface:

void error(Throwable t,String format, Object... arguments);

Usage Example This allows the user to log an error with formatting options as well as attaching an exception stack trace like so:

logger.error(throwable, "Something went wrong with the value: {} {}", value1, value2);

I believe this enhancement will make the API more flexible and user-friendly when dealing with common logging scenarios that involve both parameters and exceptions.