package com.sencorsta.rabs.obj;

import java.util.ArrayList;
import java.util.List;

/**
 * @author daibin
 */
public class LogManager {
    private static final LogManager INSTANCE = new LogManager();
    private final List<LogEventListener> logEventListeners = new ArrayList<>();

    private LogManager() {}

    public static LogManager getInstance() {
        return INSTANCE;
    }

    public void addLogEventListener(LogEventListener listener) {
        logEventListeners.add(listener);
    }

    public void removeLogEventListener(LogEventListener listener) {
        logEventListeners.remove(listener);
    }

    private void fireLogEvent(LogEvent event) {
        for (LogEventListener listener : logEventListeners) {
            listener.onLogEvent(event);
        }
    }

    public void log(String message) {
        LogEvent event = new LogEvent(this, message);
        fireLogEvent(event);
    }
}
