SLF4J extension for NoException
This extension of NoException library adds exception handlers that log all exceptions to SLF4J loggers.
Download
Get this extension from Maven Central:
Maven tool
<dependency> <groupId>com.machinezoo.noexception</groupId> <artifactId>noexception-slf4j</artifactId> <version>1.0.2</version> </dependency>
Or clone sources from GitHub or Bitbucket. Don't forget to configure your build for Java 11+. Sources and binaries are distributed under Apache License 2.0.
If your project is a Java module,
add the following declaration to your module-info.java
:
requires com.machinezoo.noexception.slf4j;
Handlers
Class ExceptionLogging
provides the following exception handlers:
log()
- Logs the exception to SLF4J and swallows it.log(Logger)
- Like above, but with custom logger.log(Logger, String)
- Like above, but with custom message.log(Logger, Supplier<String>)
- Like above, but with lazily evaluated message.
Usage
Typical usage is to catch all exceptions and log them:
System.out.println( ExceptionLogging.log().get(() -> "test".substring(5)).orElse("fallback"));
See NoException tutorial for other ways to use the handlers.