de.neuland.assertj.logging.ExpectedLogging Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of assertj-logging-log4j12 Show documentation
Show all versions of assertj-logging-log4j12 Show documentation
Logging Assertions for JUnit 4 and AssertJ
package de.neuland.assertj.logging;
import org.apache.log4j.Level;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
/**
* {@inheritDoc}
*/
public class ExpectedLogging extends GenericExpectedLogging {
private final Logger logger;
private ExpectedLogging(String loggingSource) {
super(loggingSource);
this.logger = getLogger();
}
public static ExpectedLogging forSource(Class> loggingSource) {
return new ExpectedLogging(loggingSource.getCanonicalName());
}
@Override
Log4j12LogEventCaptureAppender addCaptureAppender() {
Log4j12LogEventCaptureAppender captureAppender = new Log4j12LogEventCaptureAppender();
logger.addAppender(captureAppender);
return captureAppender;
}
@Override
void assertLoggerLevelIsAtLeastInfo() {
final Level loggerLevel = logger.getLevel();
if (loggerLevel == null || loggerLevel.isGreaterOrEqual(Level.INFO)) {
logger.setLevel(Level.INFO);
}
}
@Override
void removeCaptureAppender(final Log4j12LogEventCaptureAppender appender) {
logger.removeAppender(appender);
}
private Logger getLogger() {
return LogManager.getLogger(loggingSource);
}
}