blob: dcbc588c2780f27c9b4ff8183b4d6d071778ad16 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2004-2008 Andras Schmidt, Andras Balogh, Istvan Rath and Daniel Varro
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Andras Schmidt, Andras Balogh, Istvan Rath - initial API and implementation
*******************************************************************************/
package org.eclipse.viatra2.framework;
import java.util.ArrayList;
import org.eclipse.viatra2.framework.properties.VPMProperties;
import org.eclipse.viatra2.logger.Logger;
/**
* A VPM logger implementation, that accumulates many loggers. Loggers can be
* plugged into this logger and all output will be forwarded to all plugged
* loggers. This module is used by the VPM modeling framework to make it
* available to use more logger plugins the same time.
*
* @author Andras Schmidt
*/
public class MultiLogger implements Logger {
ArrayList<Logger> listeners = new ArrayList<Logger>();
public void setLevel(int level) {
for (Logger l : listeners) {
l.setLevel(level);
}
}
public void debug(String s) {
for (Logger l : listeners) {
l.debug(s);
}
}
public void warning(String s) {
for (Logger l : listeners) {
l.warning(s);
}
}
public void error(String s) {
for (Logger l : listeners) {
l.error(s);
}
}
public void fatal(String s) {
for (Logger l : listeners) {
l.fatal(s);
}
}
public void info(String s) {
for (Logger l : listeners) {
l.info(s);
}
}
public void init(VPMProperties p) {
}
/**
* Add a listening logger plugin.
*
* @param listener
* this plugin will get all log events from now
*/
public void addListener(Logger l) {
listeners.add(l);
}
/**
* Remove a listening logger plugin.
*
* @param listener
* this plugin will not get all log events from now
*/
void removeListener(Logger l) {
listeners.remove(l);
}
/**
* Get all listeners of this logger pipeline
*
* @returns all listeners
*/
ArrayList<Logger> getListeners() {
return listeners;
}
public void message(int level, String msg, Throwable cause) {
for (Logger l : listeners) {
l.message(level, msg, cause);
}
}
public void message(int level, String msg) {
for (Logger l : listeners) {
l.message(level, msg);
}
}
public void printStackTrace(Throwable t) {
for (Logger l : listeners)
{
l.printStackTrace(t);
}
}
}