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

com.softicar.platform.common.core.logging.LogOutputScope Maven / Gradle / Ivy

Go to download

The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.

There is a newer version: 50.0.0
Show newest version
package com.softicar.platform.common.core.logging;

import java.util.Objects;

/**
 * An {@link AutoCloseable} to conveniently control {@link CurrentLogOuput}.
 *
 * @author Oliver Richers
 */
public class LogOutputScope implements AutoCloseable {

	private final ILogOutput originalOutput;

	/**
	 * Remembers the currently defined value of {@link CurrentLogOuput#get} and
	 * defines the given {@link ILogOutput} using {@link CurrentLogOuput#set}.
	 *
	 * @param output
	 *            the new {@link ILogOutput} (never null)
	 */
	public LogOutputScope(ILogOutput output) {

		this.originalOutput = CurrentLogOuput.get();

		CurrentLogOuput.set(Objects.requireNonNull(output));
	}

	/**
	 * Resets {@link CurrentLogOuput} to its original value.
	 */
	@Override
	public void close() {

		CurrentLogOuput.set(originalOutput);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy