/*
 * Decompiled with CFR 0_110.
 * 
 * Could not load the following classes:
 *  android.util.Log
 *  java.io.IOException
 *  java.lang.IllegalArgumentException
 *  java.lang.IllegalStateException
 *  java.lang.Object
 *  java.lang.String
 *  java.lang.StringBuffer
 *  java.lang.Throwable
 *  java.util.ArrayList
 *  java.util.Iterator
 *  java.util.List
 */
package com.google.code.microlog4android;

import android.util.Log;
import com.google.code.microlog4android.Level;
import com.google.code.microlog4android.StopWatch;
import com.google.code.microlog4android.appender.Appender;
import com.google.code.microlog4android.factory.DefaultAppenderFactory;
import com.google.code.microlog4android.repository.CommonLoggerRepository;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public final class Logger {
    public static final String DEFAULT_CLIENT_ID = "Microlog";
    public static final Level DEFAULT_LOG_LEVEL = Level.DEBUG;
    private static final String TAG = "Microlog.Logger";
    private static final List<Appender> appenderList;
    private static boolean firstLogEvent;
    private static final StopWatch stopWatch;
    private String clientID = "Microlog";
    private CommonLoggerRepository commonLoggerRepository = null;
    private Level level;
    private String name;

    static {
        stopWatch = new StopWatch();
        appenderList = new ArrayList(4);
        firstLogEvent = true;
    }

    public Logger(String string2) {
        this.name = string2;
    }

    public Logger(String string2, CommonLoggerRepository commonLoggerRepository) {
        this.name = string2;
        this.commonLoggerRepository = commonLoggerRepository;
    }

    private void addDefaultAppender() {
        if (appenderList.size() == 0) {
            Log.w((String)"Microlog.Logger", (String)"Warning! No appender is set, using LogCatAppender with PatternFormatter");
            this.addAppender(DefaultAppenderFactory.createDefaultAppender());
        }
    }

    public void addAppender(Appender appender) throws IllegalArgumentException {
        if (appender == null) {
            throw new IllegalArgumentException("Appender not allowed to be null");
        }
        if (!appenderList.contains((Object)appender)) {
            appenderList.add((Object)appender);
        }
    }

    public void close() throws IOException {
        Iterator iterator = appenderList.iterator();
        do {
            if (!iterator.hasNext()) {
                stopWatch.stop();
                firstLogEvent = true;
                return;
            }
            ((Appender)iterator.next()).close();
        } while (true);
    }

    public void debug(Object object) {
        this.log(Level.DEBUG, object, null);
    }

    public void debug(Object object, Throwable throwable) {
        this.log(Level.DEBUG, object, throwable);
    }

    public void error(Object object) {
        this.log(Level.ERROR, object, null);
    }

    public void error(Object object, Throwable throwable) {
        this.log(Level.ERROR, object, throwable);
    }

    public void fatal(Object object) {
        this.log(Level.FATAL, object, null);
    }

    public void fatal(Object object, Throwable throwable) {
        this.log(Level.FATAL, object, throwable);
    }

    public Appender getAppender(int n) {
        return (Appender)appenderList.get(n);
    }

    public String getClientID() {
        return this.clientID;
    }

    public Level getEffectiveLevel() {
        Level level = this.level;
        if (level == null && !this.name.equals((Object)"")) {
            if (this.commonLoggerRepository == null) {
                throw new IllegalStateException("CommonLoggerRepository has not been set");
            }
            level = this.commonLoggerRepository.getEffectiveLevel(this.name);
        }
        return level;
    }

    public Level getLevel() {
        return this.level;
    }

    public String getName() {
        return this.name;
    }

    public int getNumberOfAppenders() {
        return appenderList.size();
    }

    public void info(Object object) {
        this.log(Level.INFO, object, null);
    }

    public void info(Object object, Throwable throwable) {
        this.log(Level.INFO, object, throwable);
    }

    public boolean isDebugEnabled() {
        if (this.getEffectiveLevel().toInt() <= 1) {
            return true;
        }
        return false;
    }

    public boolean isInfoEnabled() {
        if (this.getEffectiveLevel().toInt() <= 2) {
            return true;
        }
        return false;
    }

    public boolean isTraceEnabled() {
        if (this.getEffectiveLevel().toInt() <= 0) {
            return true;
        }
        return false;
    }

    public void log(Level level, Object object) throws IllegalArgumentException {
        this.log(level, object, null);
    }

    /*
     * Enabled aggressive block sorting
     * Enabled unnecessary exception pruning
     * Enabled aggressive exception aggregation
     */
    public void log(Level level, Object object, Throwable throwable) throws IllegalArgumentException {
        if (level == null) {
            throw new IllegalArgumentException("The level must not be null.");
        }
        if (this.getEffectiveLevel().toInt() <= level.toInt() && level.toInt() > -1) {
            if (firstLogEvent) {
                super.addDefaultAppender();
                try {
                    this.open();
                }
                catch (IOException var5_4) {
                    Log.e((String)"Microlog.Logger", (String)("Failed to open the log. " + (Object)var5_4));
                }
                stopWatch.start();
                firstLogEvent = false;
            }
            Iterator iterator = appenderList.iterator();
            while (iterator.hasNext()) {
                ((Appender)iterator.next()).doLog(this.clientID, this.name, stopWatch.getCurrentTime(), level, object, throwable);
            }
        }
    }

    void open() throws IOException {
        Iterator iterator = appenderList.iterator();
        while (iterator.hasNext()) {
            ((Appender)iterator.next()).open();
        }
        return;
    }

    public void removeAllAppenders() {
        Iterator iterator = appenderList.iterator();
        do {
            if (!iterator.hasNext()) {
                appenderList.clear();
                return;
            }
            Appender appender = (Appender)iterator.next();
            if (!appender.isLogOpen()) continue;
            try {
                appender.close();
                continue;
            }
            catch (IOException var3_2) {
                Log.e((String)"Microlog.Logger", (String)("Failed to close appender. " + (Object)var3_2));
                continue;
            }
            break;
        } while (true);
    }

    /*
     * Enabled aggressive block sorting
     * Enabled unnecessary exception pruning
     * Enabled aggressive exception aggregation
     */
    public void removeAppender(Appender appender) throws IllegalArgumentException {
        if (appender == null) {
            throw new IllegalArgumentException("The appender must not be null.");
        }
        if (appender.isLogOpen()) {
            try {
                appender.close();
            }
            catch (IOException var3_2) {
                Log.e((String)"Microlog.Logger", (String)("Failed to close appender. " + (Object)var3_2));
            }
        }
        appenderList.remove((Object)appender);
    }

    public void resetLogger() {
        Logger logger = this;
        synchronized (logger) {
            appenderList.clear();
            stopWatch.stop();
            stopWatch.reset();
            firstLogEvent = true;
            return;
        }
    }

    public void setClientID(String string2) {
        this.clientID = string2;
    }

    public void setCommonRepository(CommonLoggerRepository commonLoggerRepository) {
        void var3_2 = this;
        synchronized (var3_2) {
            this.commonLoggerRepository = commonLoggerRepository;
            return;
        }
    }

    public void setLevel(Level level) throws IllegalArgumentException {
        if (level == null) {
            throw new IllegalArgumentException("The level must not be null.");
        }
        this.level = level;
    }

    public String toString() {
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append(super.toString());
        stringBuffer.append('[');
        Iterator iterator = appenderList.iterator();
        do {
            if (!iterator.hasNext()) {
                stringBuffer.append(']');
                return stringBuffer.toString();
            }
            stringBuffer.append((Object)((Appender)iterator.next()));
            stringBuffer.append(';');
        } while (true);
    }

    public void trace(Object object) {
        this.log(Level.TRACE, object, null);
    }

    public void trace(Object object, Throwable throwable) {
        this.log(Level.TRACE, object, throwable);
    }

    public void warn(Object object) {
        this.log(Level.WARN, object, null);
    }

    public void warn(Object object, Throwable throwable) {
        this.log(Level.WARN, object, throwable);
    }
}

