apache / apache/logging-log4j2

Make `logger.error(ex);`, `logger.info(ex);`, etc. print stack trace by default

Open
#3,433 5 comments 0 reactions 0 assignees View on GitHub
waiting-for-maintainer
Dominant language
Java
Stars
3.6k
Forks
1.7k
Avg merge
21h 30m
Merged PRs (30d)
27

Description

It is too easy to write code like this:
```
try
{
doThing();
}
catch (ThingFailedException ex)
{
logger.error("Doing this thing failed.");
logger.error("Context ID: " + context.id);
logger.error("SomeSettings: " + someSetting);
logger.error(ex);
throw new WhateverException(ex);
}
```
Especially if you come back to a project after months and you don't remember anything about the log4j API specifics.
You think you you log everything you need, but you don't get the exception's stack trace here. You'd have to write `logger.error("", ex);` here, which is extremely unintuitive! Or `logger.catching(ex)`, but that's another special thing I'd need to memorize.

I propose to change the default behavior such that the stack trace is printed in this case. I don't care how it's achieved, e.g. by adding a `void error(Throwable)` overload, or adding a check in the existing `void error(Object)` overload. The point is that it should be the default behavior because that's what's expected.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.