improvements to logging
This commit is contained in:
parent
e707b564d8
commit
e11df64aee
4 changed files with 36 additions and 10 deletions
|
@ -370,7 +370,8 @@ public class ABoxUpdater {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
logger.log("Removed " + count + " subject reference" + ((count > 1) ? "s" : "") + " to the " + deletedClass.getURI() + " class");
|
//logger.log("Removed " + count + " subject reference" + ((count > 1) ? "s" : "") + " to the " + deletedClass.getURI() + " class");
|
||||||
|
logger.log(count + " subject reference" + ((count > 1) ? "s" : "") + " to the " + deletedClass.getURI() + " class " + ((count > 1) ? "were" : "was") + " removed.");
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
aboxModel.leaveCriticalSection();
|
aboxModel.leaveCriticalSection();
|
||||||
|
|
|
@ -8,6 +8,8 @@ public interface ChangeLogger {
|
||||||
|
|
||||||
public void log(String logMessage) throws IOException;
|
public void log(String logMessage) throws IOException;
|
||||||
|
|
||||||
|
public void logWithDate(String logMessage) throws IOException;
|
||||||
|
|
||||||
public void logError(String errorMessage) throws IOException;
|
public void logError(String errorMessage) throws IOException;
|
||||||
|
|
||||||
public void closeLogs() throws IOException;
|
public void closeLogs() throws IOException;
|
||||||
|
|
|
@ -9,7 +9,9 @@ import java.io.FileNotFoundException;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -59,6 +61,10 @@ public class KnowledgeBaseUpdater {
|
||||||
this.logger = new SimpleChangeLogger(settings.getLogFile(), settings.getErrorLogFile());
|
this.logger = new SimpleChangeLogger(settings.getLogFile(), settings.getErrorLogFile());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
System.out.println("Migrating the knowledge base");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
performUpdate();
|
performUpdate();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -75,6 +81,9 @@ public class KnowledgeBaseUpdater {
|
||||||
record.writeChanges();
|
record.writeChanges();
|
||||||
logger.closeLogs();
|
logger.closeLogs();
|
||||||
|
|
||||||
|
long endTime = System.currentTimeMillis();
|
||||||
|
System.out.println("Finished knowledge base migration in " + (endTime - startTime)/1000 + " seconds");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return updateRequired;
|
return updateRequired;
|
||||||
|
@ -312,13 +321,12 @@ public class KnowledgeBaseUpdater {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
Model m = settings.getOntModelSelector().getApplicationMetadataModel();
|
Model m = settings.getOntModelSelector().getApplicationMetadataModel();
|
||||||
File successAssertionsFile =
|
File successAssertionsFile = new File(settings.getSuccessAssertionsFile());
|
||||||
new File(settings.getSuccessAssertionsFile());
|
|
||||||
InputStream inStream = new FileInputStream(successAssertionsFile);
|
InputStream inStream = new FileInputStream(successAssertionsFile);
|
||||||
m.enterCriticalSection(Lock.WRITE);
|
m.enterCriticalSection(Lock.WRITE);
|
||||||
try {
|
try {
|
||||||
m.read(inStream, null, settings.getSuccessRDFFormat());
|
m.read(inStream, null, settings.getSuccessRDFFormat());
|
||||||
logger.log("Successfully finished processing ontology changes.");
|
logger.logWithDate("Successfully finished processing ontology changes.");
|
||||||
} finally {
|
} finally {
|
||||||
m.leaveCriticalSection();
|
m.leaveCriticalSection();
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,8 @@ import java.io.File;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
public class SimpleChangeLogger implements ChangeLogger {
|
public class SimpleChangeLogger implements ChangeLogger {
|
||||||
|
|
||||||
|
@ -27,18 +29,31 @@ public class SimpleChangeLogger implements ChangeLogger {
|
||||||
"files for writing", ioe);
|
"files for writing", ioe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void log(String logMessage) throws IOException {
|
public void log(String logMessage) throws IOException {
|
||||||
|
Exception e = new Exception();
|
||||||
|
StackTraceElement[] elements = e.getStackTrace();
|
||||||
|
String className = ((StackTraceElement)elements[1]).getClassName();
|
||||||
|
className = className.substring(className.lastIndexOf('.') + 1 );
|
||||||
|
//String methodName = ((StackTraceElement)elements[1]).getMethodName();
|
||||||
|
//logWriter.write(className + "." + methodName + ": " + logMessage + "\n\n");
|
||||||
|
|
||||||
|
Date now = new Date();
|
||||||
|
SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
|
||||||
|
logWriter.write(formatter.format(now) + " " + className + ": " + logMessage + "\n\n");
|
||||||
|
logWriter.flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void logWithDate(String logMessage) throws IOException {
|
||||||
|
|
||||||
Exception e = new Exception();
|
Exception e = new Exception();
|
||||||
StackTraceElement[] elements = e.getStackTrace();
|
StackTraceElement[] elements = e.getStackTrace();
|
||||||
String className = ((StackTraceElement)elements[1]).getClassName();
|
String className = ((StackTraceElement)elements[1]).getClassName();
|
||||||
className = className.substring(className.lastIndexOf('.') + 1 );
|
className = className.substring(className.lastIndexOf('.') + 1 );
|
||||||
String methodName = ((StackTraceElement)elements[1]).getMethodName();
|
Date now = new Date();
|
||||||
|
SimpleDateFormat formatter = new SimpleDateFormat("MMM dd, yyyy HH:mm:ss");
|
||||||
logWriter.write(className + ": " + logMessage + "\n\n");
|
logWriter.write(formatter.format(now) + " " + className + ": " + logMessage + "\n\n");
|
||||||
//logWriter.write(className + "." + methodName + ": " + logMessage + "\n\n");
|
logWriter.flush();
|
||||||
logWriter.flush();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void logError(String errorMessage) throws IOException {
|
public void logError(String errorMessage) throws IOException {
|
||||||
|
|
Loading…
Add table
Reference in a new issue