All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.hibernate.testing.logger.LoggerInspectionRule Maven / Gradle / Ivy

/*
 * Hibernate, Relational Persistence for Idiomatic Java
 *
 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
 * See the lgpl.txt file in the root directory or .
 */
package org.hibernate.testing.logger;

import java.util.Set;

import org.junit.rules.ExternalResource;

import org.jboss.logging.BasicLogger;

public final class LoggerInspectionRule extends ExternalResource {

	private final BasicLogger log;

	public LoggerInspectionRule(BasicLogger log) {
		this.log = log;
	}

	@Override
	protected void before() throws Throwable {
		// do nothing
	}

	@Override
	protected void after() {
		LogInspectionHelper.clearAllListeners( log );
	}

	public void registerListener(LogListener listener) {
		LogInspectionHelper.registerListener( listener, log );
	}

	public Triggerable watchForLogMessages(String prefix) {
		TriggerOnPrefixLogListener listener = new TriggerOnPrefixLogListener( prefix );
		registerListener( listener );
		return listener;
	}

	public Triggerable watchForLogMessages(Set prefixes) {
		TriggerOnPrefixLogListener listener = new TriggerOnPrefixLogListener( prefixes );
		registerListener( listener );
		return listener;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy