From 035851ba79468bfef50215a665f0317a33a1babf Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Wed, 20 May 2015 14:59:28 +0200 Subject: [PATCH] =?UTF-8?q?=C3=84nderungen=20am=20Logger.=20+=20Test=20f?= =?UTF-8?q?=C3=BCr=20Filte=20im=20Unify.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/de/dhbwstuttgart/logger/Logger.java | 65 +++++++++++++++---- .../typeinference/ConstraintsSet.java | 6 ++ .../typeinference/unify/Unify.java | 10 ++- 3 files changed, 66 insertions(+), 15 deletions(-) diff --git a/src/de/dhbwstuttgart/logger/Logger.java b/src/de/dhbwstuttgart/logger/Logger.java index dd870906..64836c07 100755 --- a/src/de/dhbwstuttgart/logger/Logger.java +++ b/src/de/dhbwstuttgart/logger/Logger.java @@ -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 logger; + private static final LogHistory LOG_HISTORY = new LogHistory(); + protected Logger(String name, LoggerConfiguration config) { this.name = name; this.logger = new HashMap<>(); @@ -26,12 +30,6 @@ public class Logger { }); } } - - /* - public static LoggerConfiguration getConfiguration(){ - return Logger.standardConfiguration; - } - */ /** * Logt eine Debug Message, welche zusätzlich einer bestimmten Section zugewiesen wird. @@ -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{ + 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 ""; + } +} diff --git a/src/de/dhbwstuttgart/typeinference/ConstraintsSet.java b/src/de/dhbwstuttgart/typeinference/ConstraintsSet.java index 49a0f5f8..c8dadca9 100755 --- a/src/de/dhbwstuttgart/typeinference/ConstraintsSet.java +++ b/src/de/dhbwstuttgart/typeinference/ConstraintsSet.java @@ -20,6 +20,12 @@ public class ConstraintsSet extends UndMenge{ this.addItems(constraint); } + public String toString(){ + String ret = ""; + + return ret; + } + /* private UndConstraint constraintsSet; diff --git a/src/de/dhbwstuttgart/typeinference/unify/Unify.java b/src/de/dhbwstuttgart/typeinference/unify/Unify.java index 858f5c35..852183a6 100755 --- a/src/de/dhbwstuttgart/typeinference/unify/Unify.java +++ b/src/de/dhbwstuttgart/typeinference/unify/Unify.java @@ -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> 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); }