Änderungen am Logger. + Test für Filte im Unify.

This commit is contained in:
JanUlrich 2015-05-20 14:59:28 +02:00
parent 4833bfd09b
commit 035851ba79
3 changed files with 66 additions and 15 deletions

View File

@ -1,6 +1,8 @@
package de.dhbwstuttgart.logger;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.logging.Handler;
import java.util.logging.Level;
@ -14,6 +16,8 @@ public class Logger {
private String name;
private final HashMap<Section, java.util.logging.Logger> logger;
private static final LogHistory LOG_HISTORY = new LogHistory();
protected Logger(String name, LoggerConfiguration config) {
this.name = name;
this.logger = new HashMap<>();
@ -27,12 +31,6 @@ public class Logger {
}
}
/*
public static LoggerConfiguration getConfiguration(){
return Logger.standardConfiguration;
}
*/
/**
* Logt eine Debug Message, welche zusätzlich einer bestimmten Section zugewiesen wird.
* Dadurch ¤sst sich die DEBUG ausgabe übersichtlicher gestalten.
@ -72,17 +70,11 @@ public class Logger {
}
protected void output(String msg , Level logLevel, Section section){
Logger.LOG_HISTORY.add(new LogLine(msg, this.name, section, logLevel));
if(logger.containsKey(section)){
java.util.logging.Logger log = logger.get(section);
log.log(logLevel, msg);
}
/*
if(output != null){
output.println(msg);
}else if(standardOutput != null){
standardOutput.println(msg);
}
*/
}
public void info(String message, Section s) {
@ -100,6 +92,12 @@ public class Logger {
Logger.standardConfiguration = config;
}
public static String getWholeLog(){
String ret = "";
Logger.LOG_HISTORY.sort((log1, log2)->log1.timestamp.compareTo(log2.timestamp));
ret += Logger.LOG_HISTORY.toString();
return ret;
}
}
class OutputHandler extends Handler{
@ -123,3 +121,44 @@ class OutputHandler extends Handler{
public void close() throws SecurityException {
}
}
class LogHistory extends ArrayList<LogLine>{
private static final long serialVersionUID = -1785228323497318261L;
@Override
public String toString(){
String ret = "";
for(LogLine l : this){
ret += l.toString() + "\n";
}
return ret;
}
}
class LogLine {
Date timestamp;
String message;
String name;
Section section;
Level level;
LogLine(String msg, String loggerName, Section section, Level logLevel){
this.timestamp = new Date();
this.message = msg;
this.name = loggerName;
this.section = section;
this.level = logLevel;
}
public String toString(){
String ret = "";
ret += name + ": ";
ret += message;
ret += " - " + section.name();
return ret;
}
public String toJSON(){
return "";
}
}

View File

@ -20,6 +20,12 @@ public class ConstraintsSet extends UndMenge<Pair>{
this.addItems(constraint);
}
public String toString(){
String ret = "";
return ret;
}
/*
private UndConstraint constraintsSet;

View File

@ -56,7 +56,7 @@ public class Unify
{
// ino.attribute.inferencelog.28052.declaration
protected static SectionLogger inferencelog = Logger.getSectionLogger("inference", Section.UNIFY);
protected static SectionLogger inferencelog = Logger.getSectionLogger(Unify.class.getName(), Section.UNIFY);
// ino.end
/**
@ -644,13 +644,19 @@ public class Unify
}
cSet.addItems(orConstraints);
}
if(filter){
SectionLogger log = Logger.getSectionLogger(Unify.class.getName(), Section.UNIFY);
Unifier filterUnify = (pairs)->{
String pairsString = pairs.toString();
Menge<Menge<Pair>> retValue = new Menge<>();
retValue = Unify.unifyFiltered(pairs,fc_tto,false);
//Unify.unify(pairs, fc_tto, (i)->{});
log.debug("Filtere Constraints:\n"+pairsString);
log.debug("Ergebnis: "+ retValue);
return retValue;};
log.debug("Filtere 'WrongConstraints' auf: "+cSet);
cSet.filterWrongConstraints(filterUnify);
}