summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/App.java
diff options
context:
space:
mode:
authorJonathan Bauer2014-09-22 16:55:49 +0200
committerJonathan Bauer2014-09-22 16:55:49 +0200
commit8379b2e4a5dd76fcbd344b7a152dc14629f64ae9 (patch)
tree3b5082edd282f0143b5ea67ebf3f0956b8eed814 /dozentenmodul/src/main/java/App.java
parent[client] NEW: Logging mechanisms for the client (diff)
downloadtutor-module-8379b2e4a5dd76fcbd344b7a152dc14629f64ae9.tar.gz
tutor-module-8379b2e4a5dd76fcbd344b7a152dc14629f64ae9.tar.xz
tutor-module-8379b2e4a5dd76fcbd344b7a152dc14629f64ae9.zip
[client] do commit the changes :)
Diffstat (limited to 'dozentenmodul/src/main/java/App.java')
-rw-r--r--dozentenmodul/src/main/java/App.java62
1 files changed, 52 insertions, 10 deletions
diff --git a/dozentenmodul/src/main/java/App.java b/dozentenmodul/src/main/java/App.java
index 10b9a460..0d3e0124 100644
--- a/dozentenmodul/src/main/java/App.java
+++ b/dozentenmodul/src/main/java/App.java
@@ -1,29 +1,71 @@
import gui.intro.Login_GUI;
import java.awt.EventQueue;
+import java.io.File;
import java.io.IOException;
import javax.swing.JOptionPane;
+import org.apache.log4j.FileAppender;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+
import config.Config;
public class App {
+ // Logger
+ private final static Logger LOGGER = Logger.getLogger(App.class);
+
+ private static void setupLogger() {
+
+ // path to the log file
+ final String logFilePath = Config.getPath() + System.getProperty("file.separator") + "bwSuite.log";
+
+ // check if we had an old log file
+ final File logFile = new File(logFilePath);
+ if (logFile.exists() && !logFile.isDirectory()) {
+ // we have one, rename it to 'bwSuite.log.old'
+ try {
+ logFile.renameTo(new File(logFilePath + ".old"));
+ } catch (Exception e) {
+ LOGGER.error("Could not move '" + logFilePath +
+ "' to '" + logFilePath + ".old':");
+ e.printStackTrace();
+ }
+ }
+
+ // add file appender to global logger
+ FileAppender fa = null;
+ try {
+ fa = new FileAppender(new PatternLayout("%d [%F:%M] %m%n"), Config.getPath() + System.getProperty("file.separator") + "bwSuite.log");
+ LOGGER.addAppender(fa);
+ LOGGER.info("Starting logging to: " + Config.getPath() + System.getProperty("file.separator") + "bwSuite.log");
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ LOGGER.info("Logger initialised.");
+ }
+
public static void main(String[] args) {
+
+ // Pruefe und Erzeuge gegebenfalls Config
+ try {
+ Config.init();
+ } catch (IOException e) {
+ e.printStackTrace();
+ JOptionPane.showMessageDialog(null, e.getMessage(),
+ "Fehler", JOptionPane.ERROR_MESSAGE);
+ return;
+ }
+
+ setupLogger();
+
+ // start the GUI
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
- // Pruefe und Erzeuge gegebenfalls Config
- try {
- Config.init();
- } catch (IOException e) {
- e.printStackTrace();
- JOptionPane.showMessageDialog(null, e.getMessage(),
- "Fehler", JOptionPane.ERROR_MESSAGE);
- return;
- }
-
// Aufruf und Anzeige des Login Fensters
Login_GUI frame = new Login_GUI();
frame.setVisible(true);