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

de.intarsys.tools.logging.CompositeHandler Maven / Gradle / Ivy

There is a newer version: 4.11
Show newest version
package de.intarsys.tools.logging;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Handler;
import java.util.logging.LogRecord;

/**
 * A Java logging {@link Handler} that forwards to a collection of other
 * {@link Handler} instances.
 * 
 */
public class CompositeHandler extends Handler {

	private List handlers = new ArrayList();

	public void addHandler(Handler handler) {
		handlers.add(handler);
	}

	@Override
	public void close() throws SecurityException {
		for (Handler handler : handlers) {
			handler.close();
		}
	}

	@Override
	public void flush() {
		for (Handler handler : handlers) {
			handler.flush();
		}
	}

	public Handler[] getHandlers() {
		return handlers.toArray(new Handler[handlers.size()]);
	}

	@Override
	public void publish(LogRecord record) {
		for (Handler handler : handlers) {
			handler.publish(record);
		}
	}

	public void removeHandler(Handler handler) {
		handlers.remove(handler);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy