001 /* This file is part of the project "Hilbert II" - http://www.qedeq.org
002 *
003 * Copyright 2000-2013, Michael Meyling <mime@qedeq.org>.
004 *
005 * "Hilbert II" is free software; you can redistribute
006 * it and/or modify it under the terms of the GNU General Public
007 * License as published by the Free Software Foundation; either
008 * version 2 of the License, or (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013 * GNU General Public License for more details.
014 */
015
016 package org.qedeq.kernel.bo.log;
017
018 import java.util.ArrayList;
019 import java.util.List;
020
021 import org.qedeq.base.trace.Trace;
022
023
024 /**
025 * This class organizes the logging.
026 *
027 * TODO 20110606 m31: this class is a singleton but it would be better if it is not
028 * to accomplish this we must put a getLogInstance method in all
029 * important BO classes.
030 *
031 * @author Michael Meyling
032 */
033 public final class QedeqLog implements LogListener {
034
035 /** This class. */
036 private static final Class CLASS = QedeqLog.class;
037
038 /** The one and only instance. */
039 private static QedeqLog instance = new QedeqLog();
040
041 /** The loggers. */
042 private List loggers = new ArrayList();
043
044
045 /**
046 * Get instance of Logger.
047 *
048 * @return singleton
049 */
050 public static final QedeqLog getInstance() {
051 return instance;
052 }
053
054
055 /**
056 * Don't use me outside of this class.
057 */
058 private QedeqLog() {
059 }
060
061 /**
062 * Add listener.
063 *
064 * @param log Add this listener.
065 */
066 public synchronized void addLog(final LogListener log) {
067 loggers.add(log);
068 Trace.paramInfo(CLASS, this, "addLog(LogListener)", "log", log.getClass());
069 }
070
071 /**
072 * Remove listener.
073 *
074 * @param log Remove this listener.
075 */
076 public synchronized void removeLog(final LogListener log) {
077 loggers.remove(log);
078 Trace.paramInfo(CLASS, this, "removeLog(LogListener)", "log", log.getClass());
079 }
080
081 public synchronized void logMessageState(final String text, final String url) {
082 for (int i = 0; i < loggers.size(); i++) {
083 try { // we don't know if the LogListener is free of programming errors...
084 ((LogListener) loggers.get(i)).logMessageState(text, url);
085 } catch (RuntimeException e) {
086 Trace.fatal(CLASS, this, "logMessageState", "LogListener throwed RuntimeException",
087 e);
088 }
089 }
090 }
091
092 public synchronized void logFailureState(final String text, final String url, final String description) {
093 for (int i = 0; i < loggers.size(); i++) {
094 try { // we don't know if the LogListener is free of programming errors...
095 ((LogListener) loggers.get(i)).logFailureState(text, url, description);
096 } catch (RuntimeException e) {
097 Trace.fatal(CLASS, this, "logFailureState", "LogListener throwed RuntimeException",
098 e);
099 }
100 }
101 }
102
103 public synchronized void logSuccessfulState(final String text, final String url) {
104 for (int i = 0; i < loggers.size(); i++) {
105 try { // we don't know if the LogListener is free of programming errors...
106 ((LogListener) loggers.get(i)).logSuccessfulState(text, url);
107 } catch (RuntimeException e) {
108 Trace.fatal(CLASS, this, "logSuccessfulState",
109 "LogListener throwed RuntimeException", e);
110 }
111 }
112 }
113
114 public synchronized void logRequest(final String text, final String url) {
115 for (int i = 0; i < loggers.size(); i++) {
116 try { // we don't know if the LogListener is free of programming errors...
117 ((LogListener) loggers.get(i)).logRequest(text, url);
118 } catch (RuntimeException e) {
119 Trace.fatal(CLASS, this, "logRequest", "LogListener throwed RuntimeException", e);
120 }
121 }
122 }
123
124 public synchronized void logSuccessfulReply(final String text, final String url) {
125 try { // we don't know if the LogListener is free of programming errors...
126 for (int i = 0; i < loggers.size(); i++) {
127 ((LogListener) loggers.get(i)).logSuccessfulReply(text, url);
128 }
129 } catch (RuntimeException e) {
130 Trace.fatal(CLASS, this, "logSuccessfulReply", "LogListener throwed RuntimeException",
131 e);
132 }
133 }
134
135 public synchronized void logFailureReply(final String text, final String url, final String description) {
136 for (int i = 0; i < loggers.size(); i++) {
137 try { // we don't know if the LogListener is free of programming errors...
138 ((LogListener) loggers.get(i)).logFailureReply(text, url, description);
139 } catch (RuntimeException e) {
140 Trace.fatal(CLASS, this, "logFailureReply", "LogListener throwed RuntimeException",
141 e);
142 }
143 }
144 }
145
146 public synchronized void logMessage(final String text) {
147 for (int i = 0; i < loggers.size(); i++) {
148 try { // we don't know if the LogListener is free of programming errors...
149 ((LogListener) loggers.get(i)).logMessage(text);
150 } catch (RuntimeException e) {
151 Trace.fatal(CLASS, this, "logMessage", "LogListener throwed RuntimeException", e);
152 }
153 }
154 }
155
156
157 }
|