Search in sources :

Example 1 with LogFormat

use of de.Keyle.MyPet.api.util.LogFormat in project MyPet by xXKeyleXx.

the class MyPetLogger method setupDebugLogger.

protected boolean setupDebugLogger() {
    if (getHandlers().length > 0) {
        for (Handler h : getHandlers()) {
            if (h.toString().equals("MyPet-Debug-Logger-FileHandler")) {
                if (Configuration.Log.LEVEL.equalsIgnoreCase("OFF")) {
                    removeHandler(h);
                    h.close();
                    return false;
                }
                debugLogFileHandler = (FileHandler) h;
                return true;
            }
        }
    }
    if (Configuration.Log.LEVEL.equalsIgnoreCase("OFF")) {
        return false;
    }
    if (debugLogFileHandler != null) {
        addHandler(debugLogFileHandler);
        return true;
    }
    try {
        File logsFolder = new File(MyPetApi.getPlugin().getDataFolder(), "logs");
        logsFolder.mkdirs();
        File logFile = new File(logsFolder, File.separator + "MyPet.log");
        FileHandler fileHandler = new FileHandler(logFile.getAbsolutePath(), true) {

            @Override
            public String toString() {
                return "MyPet-Debug-Logger-FileHandler";
            }
        };
        Level level;
        try {
            level = Level.parse(Configuration.Log.LEVEL);
        } catch (IllegalArgumentException e) {
            level = Level.OFF;
            this.warning(e.getMessage());
        }
        fileHandler.setLevel(level);
        System.out.println("Level: " + level);
        fileHandler.setFormatter(new LogFormat());
        addHandler(fileHandler);
        debugLogFileHandler = fileHandler;
        return true;
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }
}
Also used : LogFormat(de.Keyle.MyPet.api.util.LogFormat) FileHandler(java.util.logging.FileHandler) Handler(java.util.logging.Handler) Level(java.util.logging.Level) IOException(java.io.IOException) File(java.io.File) FileHandler(java.util.logging.FileHandler)

Aggregations

LogFormat (de.Keyle.MyPet.api.util.LogFormat)1 File (java.io.File)1 IOException (java.io.IOException)1 FileHandler (java.util.logging.FileHandler)1 Handler (java.util.logging.Handler)1 Level (java.util.logging.Level)1