log.slf4j
Programmatic logging control for test support
Provides:
-
Programmatic logging control that plays nice with slf4j-simple’s system properties
-
Simple log capture - lamdba/Runnable to String
-
Transitively pulls in every available SLF4J binding:
-
Configures log bridges for some popular frameworks that don’t use SLF4J by default:
It’s advisable to configure this logging before anything else (Note; it will override anything already set for these “known” properties).
Existing log levels (including the default) set as system properties will not be overridden. So you may, for example, choose to use Maven profiles, setting properties to override specific levels.
For details of slf4j-simple’s system properties, see: SimpleLogger JavaDoc
Brief Examples
1. Programmatically Initialize
logging() .configureFrameworks() .defaultLevel(INFO) .log("com.acme").at(DEBUG) .log(getClass()).at(TRACE) .log("com.annoying").at(ERROR);
2. Capture
Logger acmeLogger = LoggerFactory.getLogger("com.acme"); String wee = "Weeeeeeeeeee!"; String captured = Logging.capture(() -> acmeLogger.info(wee)); assertThat(captured, containsString(wee));
Static Imports
import static io.earcam.utilitarian.log.slf4j.Level.DEBUG; import static io.earcam.utilitarian.log.slf4j.Level.ERROR; import static io.earcam.utilitarian.log.slf4j.Level.INFO; import static io.earcam.utilitarian.log.slf4j.Level.TRACE; import static io.earcam.utilitarian.log.slf4j.Logging.logging; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.not;