summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/App.java
diff options
context:
space:
mode:
authorJonathan Bauer2015-06-22 13:40:02 +0200
committerJonathan Bauer2015-06-22 13:40:02 +0200
commitbb09d09546c00fe8b0c21d525af31c87097367d4 (patch)
tree61fd648989bcde8ed32b3bf426870d9846e948cb /dozentenmodul/src/main/java/App.java
parent[server] Implement getOperatingSystems and getVirtualizers (diff)
downloadtutor-module-bb09d09546c00fe8b0c21d525af31c87097367d4.tar.gz
tutor-module-bb09d09546c00fe8b0c21d525af31c87097367d4.tar.xz
tutor-module-bb09d09546c00fe8b0c21d525af31c87097367d4.zip
[client] rebasing the whole app...
Diffstat (limited to 'dozentenmodul/src/main/java/App.java')
-rw-r--r--dozentenmodul/src/main/java/App.java113
1 files changed, 72 insertions, 41 deletions
diff --git a/dozentenmodul/src/main/java/App.java b/dozentenmodul/src/main/java/App.java
index 0eb9b847..96c9c335 100644
--- a/dozentenmodul/src/main/java/App.java
+++ b/dozentenmodul/src/main/java/App.java
@@ -1,17 +1,18 @@
-import java.awt.EventQueue;
+import gui.GuiManager;
+
import java.io.File;
import java.io.IOException;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
-import javax.swing.JOptionPane;
-
+import org.apache.commons.io.FileUtils;
+import org.apache.log4j.AppenderSkeleton;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.FileAppender;
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;
-import org.openslx.thrifthelper.ThriftManager;
-import org.openslx.thrifthelper.ThriftManager.ErrorCallback;
+import org.apache.log4j.spi.LoggingEvent;
-import util.GuiManager;
import config.Config;
import config.ConfigProxy;
@@ -29,11 +30,14 @@ public class App {
final File logFile = new File(logFilePath);
if (logFile.exists() && !logFile.isDirectory()) {
// we have one, rename it to 'bwSuite.log.old'
+ LOGGER.info("renaming old log file");
try {
- logFile.renameTo(new File(logFilePath + ".old"));
+ File oldFile = new File(logFilePath + ".old");
+ FileUtils.forceDelete(oldFile);
+ logFile.renameTo(oldFile);
+ FileUtils.forceDelete(logFile);
} catch (Exception e) {
- LOGGER.error("Could not move '" + logFilePath + "' to '" + logFilePath + ".old':");
- e.printStackTrace();
+ LOGGER.error("Could not move '" + logFilePath + "' to '" + logFilePath + ".old'", e);
}
}
@@ -42,12 +46,49 @@ public class App {
try {
fa = new FileAppender(new PatternLayout("%d [%F:%M] %m%n"), logFilePath);
// All classes should log to file, configure global file appender.
- BasicConfigurator.configure(fa);
- LOGGER.info("Starting logging to: " + logFilePath);
} catch (IOException e) {
e.printStackTrace();
+ BasicConfigurator.configure();
+ return;
}
- LOGGER.info("Logger initialised.");
+
+ final FileAppender ffa = fa;
+ final Pattern re = Pattern.compile("authorization:(\\w|\\+|/|\\s)+", Pattern.CASE_INSENSITIVE
+ | Pattern.MULTILINE);
+
+ AppenderSkeleton ap = new AppenderSkeleton() {
+
+ @Override
+ public boolean requiresLayout() {
+ return ffa.requiresLayout();
+ }
+
+ @Override
+ public void close() {
+ ffa.close();
+ }
+
+ @Override
+ protected void append(LoggingEvent event) {
+ String s = event.getRenderedMessage();
+ if (s.contains("uthorization")) {
+ Matcher m = re.matcher(s);
+ if (!m.find()) {
+ LOGGER.warn("Could not match pattern!");
+ } else {
+ s = m.replaceAll("Authorization: ***********");
+ LOGGER.info("Patched log message");
+ }
+ }
+ ffa.append(new LoggingEvent(event.getFQNOfLoggerClass(), event.getLogger(),
+ event.getTimeStamp(), event.getLevel(), s, event.getThreadName(),
+ event.getThrowableInformation(), event.getNDC(), event.getLocationInformation(),
+ event.getProperties()));
+ }
+ };
+
+ BasicConfigurator.configure(ap);
+ LOGGER.info("Starting logging to: " + logFilePath);
}
public static void main(final String[] args) {
@@ -57,7 +98,6 @@ public class App {
Config.init();
} catch (IOException e) {
e.printStackTrace();
- JOptionPane.showMessageDialog(null, e.getMessage(), "Fehler", JOptionPane.ERROR_MESSAGE);
return;
}
@@ -70,35 +110,26 @@ public class App {
LOGGER.error("IOException when trying to initialise the proxy, see trace: ", e);
}
- // Set up thrift error message displaying
- ThriftManager.setErrorCallback(new ErrorCallback() {
-
- @Override
- public void thriftError(Throwable t, String message) {
- EventQueue.invokeLater(new Runnable() {
-
- @Override
- public void run() {
- JOptionPane.showMessageDialog(null, "Die Kommunikation mit dem Server ist fehlgeschlagen.\n"
- + "Bitte stellen Sie sicher, dass Sie mit dem Internet verbunden sind.\n"
- + "Sofern das Problem weiterhin besteht, liegt möglicherweise eine serverseitige\n"
- + "Störung vor.", "Fehler", JOptionPane.ERROR_MESSAGE);
- }
- });
- }
- });
+// // Set up thrift error message displaying
+// ThriftManager.setErrorCallback(new ErrorCallback() {
+//
+// @Override
+// public void thriftError(Throwable t, String message) {
+// EventQueue.invokeLater(new Runnable() {
+//
+// @Override
+// public void run() {
+// JOptionPane.showMessageDialog(null, "Die Kommunikation mit dem Server ist fehlgeschlagen.\n"
+// + "Bitte stellen Sie sicher, dass Sie mit dem Internet verbunden sind.\n"
+// + "Sofern das Problem weiterhin besteht, liegt möglicherweise eine serverseitige\n"
+// + "Störung vor.", "Fehler", JOptionPane.ERROR_MESSAGE);
+// }
+// });
+// }
+// });
// start the GUI
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- GuiManager.initGui();
- } catch (Exception e) {
- e.printStackTrace();
- JOptionPane.showMessageDialog(null, e.getStackTrace(), "Message", JOptionPane.ERROR_MESSAGE);
- }
- }
+ GuiManager.initGui();
- });
}
-}
+} \ No newline at end of file