Skip to content

Add Logback's throwable-consuming semantics as an option #2363

@SeasonPanPan

Description

@SeasonPanPan

Description

Hello, we used to use logback in our springboot project, recently migrated to log4j2 and we found that a lot of the exception stack is gone.

For example, in the following example, using logback, you can clearly see the error stack, but log4j2 only has one sentence "java.lang.NullPointerException", I read the source code of log4j2 and feel that this should be a bug. I also test it with version:2.23.1, and the same error.
Additionally, I found that these classes are correct: MessageFormatMessage and StringFormattedMessage.

If you can confirm that this is a bug, I'd be pleasure to submit a PR to fix it.

Configuration

Version: 2.23.1

Operating system: windows/Linux

JDK: "1.8.0_291"

Logs

==> log4j2 result:

20:32:33.887 [main] [ERROR] com.pandas.springboot.demo.DemoApplicationTests - fail to process null, the error is:java.lang.NullPointerException

==> logback result:
2024-03-11 20:37:35.173 ERROR 16840 --- [           main] c.p.s.demo.DemoApplicationTests          : fail to process null, the error is:{}

java.lang.NullPointerException: null
	at com.pandas.springboot.demo.DemoApplicationTests.log(DemoApplicationTests.java:20) [test-classes/:na]
	at com.pandas.springboot.demo.DemoApplicationTests.testLog(DemoApplicationTests.java:15) [test-classes/:na]
	

Reproduction

@SpringBootTest
public class DemoApplicationTests {

	private static final Logger log = LoggerFactory.getLogger(DemoApplicationTests.class);

	@Test
	public void testLog() {
		log(null);
	}

	private static void log(String param) {
		try {
			int b = param.length();
		} catch (Exception e) {
			log.error("fail to process {}, the error is:{}", param, e);
		}
	}
}

Metadata

Metadata

Assignees

Labels

apiAffects the public APIbugIncorrect, unexpected, or unintended behavior of existing code

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions