qos-ch / slf4j

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

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

Open ThinkPeace opened 9 months ago

ThinkPeace commented 9 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.

ExE-Boss commented 3 days ago

This is already supported, just call the existing varargs method with the Throwable as the last element in the varargs array.