forked from LupusNobilis/java-org.hwo
LoggingListener neu
parent
bd9472b39b
commit
c516ddf235
|
@ -7,6 +7,8 @@ import java.io.OutputStream;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class Logging {
|
public class Logging {
|
||||||
|
|
||||||
|
@ -17,7 +19,11 @@ public class Logging {
|
||||||
private PrintStream logStream;
|
private PrintStream logStream;
|
||||||
private final DateFormat dateFormat;
|
private final DateFormat dateFormat;
|
||||||
|
|
||||||
|
List<LoggingListener> loggingListeners;
|
||||||
|
|
||||||
public Logging(String filename){
|
public Logging(String filename){
|
||||||
|
loggingListeners = new LinkedList<LoggingListener>();
|
||||||
|
|
||||||
dateFormat = DateFormat.getDateTimeInstance();
|
dateFormat = DateFormat.getDateTimeInstance();
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
@ -44,6 +50,13 @@ public class Logging {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addLoggingListener(LoggingListener listener){
|
||||||
|
loggingListeners.add(listener);
|
||||||
|
}
|
||||||
|
public void removeLoggingListener(LoggingListener listener){
|
||||||
|
loggingListeners.remove(listener);
|
||||||
|
}
|
||||||
|
|
||||||
private void _log(LogLevel logLevel,String message){
|
private void _log(LogLevel logLevel,String message){
|
||||||
String formattedLine;
|
String formattedLine;
|
||||||
|
|
||||||
|
@ -56,6 +69,10 @@ public class Logging {
|
||||||
liveStream.println(formattedLine);
|
liveStream.println(formattedLine);
|
||||||
liveStream.flush();
|
liveStream.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (LoggingListener l: loggingListeners){
|
||||||
|
l.logMessageArrived(formattedLine);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -87,6 +104,10 @@ public class Logging {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static public Logging getInstance() {
|
||||||
|
return _inst;
|
||||||
|
}
|
||||||
|
|
||||||
static {
|
static {
|
||||||
liveStream = System.out;
|
liveStream = System.out;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
package org.hwo.logging;
|
||||||
|
|
||||||
|
public interface LoggingListener {
|
||||||
|
|
||||||
|
public void logMessageArrived(String message);
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue