package org.bdgp.MMSlide;

import java.util.Date;
import java.util.List;

import org.bdgp.MMSlide.DB.Log;

public class Logger {
    public static enum Level {ALL, SEVERE, WARNING, INFO, CONFIG, FINE, FINER, FINEST, OFF};
    private List<LogListener> logListeners;
    private Dao<Log> logger;
    private String source;
    private Level loglevel;
    public Logger(String logfile, String source, Level loglevel) {
        this.logger = Connection.file(Log.class, logfile);
        this.source = source;
        this.loglevel = loglevel != null ? loglevel : Level.INFO;
    }
    public void addListener(LogListener listener) {
        this.logListeners.add(listener);
    }
    public void removeListener(LogListener listener) {
        this.logListeners.remove(listener);
    }
    public void log(Level loglevel, String message) {
        if (this.loglevel.compareTo(loglevel) <= 0) {
            Log log = new Log(source, new Date(), loglevel, message);
            this.logger.insert(log);
            for (LogListener logListener : logListeners) {
                logListener.log(log);
            }
        }
    }
    public void severe(String message) {log(Level.SEVERE, message);}
    public void warning(String message) {log(Level.WARNING, message);}
    public void info(String message) {log(Level.INFO, message);}
    public void config(String message) {log(Level.CONFIG, message);}
    public void fine(String message) {log(Level.FINE, message);}
    public void finer(String message) {log(Level.FINER, message);}
    public void finest(String message) {log(Level.FINEST, message);}
    
}

@@ -20,16 +20,102 @@
 Slide;%0A%0A
+import java.io.BufferedWriter;%0Aimport java.io.FileWriter;%0Aimport java.io.IOException;%0A
 import j
@@ -129,16 +129,16 @@
 l.Date;%0A
-
 import j
@@ -349,37 +349,8 @@
 rs;%0A
-    private Dao%3CLog%3E logger;%0A
     
@@ -400,16 +400,53 @@
 glevel;%0A
+    private BufferedWriter log;%0A    %0A
     publ
@@ -508,67 +508,8 @@
 ) %7B%0A
-        this.logger = Connection.file(Log.class, logfile);%0A
     
@@ -600,16 +600,153 @@
 l.INFO;%0A
+        try %7B this.log = new BufferedWriter(new FileWriter(logfile)); %7D%0A        catch (IOException e) %7B throw new RuntimeException(e); %7D%0A
     %7D%0A  
@@ -1132,24 +1132,30 @@
 %0A           
+ try %7B
  this.logger
@@ -1155,24 +1155,136 @@
 .log
-ger.insert(log);
+.write(log.toString()); this.log.newLine(); %7D %0A            catch (IOException e) %7B throw new RuntimeException(e); %7D%0A            
 %0A   

write log files directly instead of using ORM