package de.greenrobot.event;

import android.util.Log;

import java.util.logging.Level;

public abstract class Logger {
    private static final boolean useAndroidLog;
    private static volatile Logger DEFAULT_LOGGER;


    static {
        boolean android = false;
        try {
            android = Class.forName("android.util.Log") != null;
        } catch (ClassNotFoundException e) {
            // OK
        }
        useAndroidLog = android;
    }


    public static synchronized Logger initDefaultLogger(String tag) {
        if (DEFAULT_LOGGER != null) {
            throw new IllegalStateException("Default logger already set up");
        }
        DEFAULT_LOGGER = create(tag);
        return DEFAULT_LOGGER;
    }

    public static Logger get() {
        if (DEFAULT_LOGGER == null) {
            throw new IllegalStateException("Default logger must be initialized before");
        }
        return DEFAULT_LOGGER;
    }

    public static Logger create(String tag) {
        if (useAndroidLog) {
            return new AndroidLogger(tag);
        } else {
            return new JavaLogger(tag);
        }
    }

    public abstract boolean isLoggable(Level level);

    public abstract void log(Level level, String msg);

    public abstract void log(Level level, String msg, Throwable th);

    public static class AndroidLogger extends Logger {
        private final String tag;

        public AndroidLogger(String tag) {
            this.tag = tag;
        }

        public boolean isLoggable(Level level) {
            if (level == Level.OFF) {
                return false;
            } else {
                return Log.isLoggable(tag, mapLevel(level));
            }
        }

        public void log(Level level, String msg) {
            if (level != Level.OFF) {
                Log.println(mapLevel(level), tag, msg);
            }
        }

        public void log(Level level, String msg, Throwable th) {
            if (level != Level.OFF) {
                // That's how Log does it internally
                Log.println(mapLevel(level), tag, msg + "\n" + Log.getStackTraceString(th));
            }
        }

        protected int mapLevel(Level level) {
            if (level == Level.OFF) {
                return 0;
            } else if (level == Level.FINEST || level == Level.FINER) {
                return Log.VERBOSE;
            } else if (level == Level.FINE || level == Level.CONFIG) {
                return Log.DEBUG;
            } else if (level == Level.INFO) {
                return Log.INFO;
            } else if (level == Level.WARNING) {
                return Log.WARN;
            } else if (level == Level.SEVERE) {
                return Log.ERROR;
            } else if (level == Level.ALL) {
                // Hmm, well..
                return Log.ASSERT;
            } else {
                throw new IllegalArgumentException("Unexpected level: " + level);
            }
        }

    }

    public static class JavaLogger extends Logger {
        protected final java.util.logging.Logger logger;

        public JavaLogger(String tag) {
            logger = java.util.logging.Logger.getLogger(tag);
        }

        @Override
        public boolean isLoggable(Level level) {
            return logger.isLoggable(level);
        }

        @Override
        public void log(Level level, String msg) {
            logger.log(level, msg);
        }

        @Override
        public void log(Level level, String msg, Throwable th) {
            logger.log(level, msg, th);
        }

    }
}

@@ -165,60 +165,8 @@
 og;%0A
-    private static volatile Logger DEFAULT_LOGGER;%0A%0A
 %0A   
@@ -404,490 +404,8 @@
  %7D%0A%0A
-%0A    public static synchronized Logger initDefaultLogger(String tag) %7B%0A        if (DEFAULT_LOGGER != null) %7B%0A            throw new IllegalStateException(%22Default logger already set up%22);%0A        %7D%0A        DEFAULT_LOGGER = create(tag);%0A        return DEFAULT_LOGGER;%0A    %7D%0A%0A    public static Logger get() %7B%0A        if (DEFAULT_LOGGER == null) %7B%0A            throw new IllegalStateException(%22Default logger must be initialized before%22);%0A        %7D%0A        return DEFAULT_LOGGER;%0A    %7D%0A%0A
     
@@ -1675,131 +1675,133 @@
    i
-f (level == Level.OFF) %7B%0A                return 0;%0A            %7D else if (level == Level.FINEST %7C%7C level == Level.FINER) %7B%0A
+nt value = level.intValue();%0A            if (value %3C 800) %7B // below INFO%0A                if (value %3C 500) %7B // below FINE%0A  
     
@@ -1804,32 +1804,34 @@
                 
+  
 return Log.VERBO
@@ -1850,228 +1850,131 @@
     
-%7D else if (level == Level.FINE %7C%7C level == Level.CONFIG) %7B%0A                return Log.DEBUG;%0A            %7D else if (level == Level.INFO) %7B%0A                return Log.INFO;%0A            %7D else if (level == Level.
+    %7D else %7B%0A                    return Log.DEBUG;%0A                %7D%0A            %7D else if (value %3C 900) %7B // below 
 WARNING
-) %7B
 %0A   
@@ -1997,20 +1997,20 @@
 urn Log.
-WARN
+INFO
 ;%0A      
@@ -2030,142 +2030,38 @@
 if (
-level == Level.SEVERE) %7B%0A                return Log.ERROR;%0A            %7D else if (level == Level.ALL) %7B%0A                // Hmm, well..
+value %3C 1000) %7B // below ERROR
 %0A   
@@ -2088,14 +2088,12 @@
 Log.
-ASSERT
+WARN
 ;%0A  
@@ -2131,72 +2131,24 @@
     
-throw new IllegalArgumentException(%22Unexpected level: %22 + level)
+return Log.ERROR
 ;%0A  
@@ -2165,25 +2165,24 @@
 %7D%0A        %7D%0A
-%0A
     %7D%0A%0A    p

remove DEFAULT_LOGGER, map level based on intValue