package com.bytedance.bae.base;

import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.EnumSet;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Logging {
    public static final Logger fallbackLogger = createFallbackLogger();
    public static Loggable loggable;
    public static Severity loggableSeverity;
    public static volatile boolean loggingEnabled;

    public enum Severity {
        LS_DEBUG,
        LS_TRACE,
        LS_INFO,
        LS_WARNING,
        LS_ERROR,
        LS_NONE
    }

    public static void deleteInjectedLoggable() {
        loggable = null;
    }

    public static void enableTracing(String str, EnumSet<TraceLevel> enumSet) {
    }

    public static native void nativeEnableLogThreads();

    public static native void nativeEnableLogTimeStamps();

    public static native void nativeEnableLogToDebugOutput(int i);

    public static native void nativeLog(int i, String str, String str2);

    static {
        Covode.recordClassIndex(24198);
    }

    public static Logger createFallbackLogger() {
        Logger logger = Logger.getLogger("org.webrtc.Logging");
        logger.setLevel(Level.ALL);
        return logger;
    }

    public static void enableLogThreads() {
        MethodCollector.i(16703);
        nativeEnableLogThreads();
        MethodCollector.o(16703);
    }

    public static void enableLogTimeStamps() {
        MethodCollector.i(16705);
        nativeEnableLogTimeStamps();
        MethodCollector.o(16705);
    }

    /* renamed from: com.bytedance.bae.base.Logging$1  reason: invalid class name */
    public static /* synthetic */ class AnonymousClass1 {
        public static final /* synthetic */ int[] $SwitchMap$com$bytedance$bae$base$Logging$Severity;

        /* JADX WARNING: Can't wrap try/catch for region: R(8:0|1|2|3|4|5|6|8) */
        /* JADX WARNING: Code restructure failed: missing block: B:9:?, code lost:
            return;
         */
        /* JADX WARNING: Failed to process nested try/catch */
        /* JADX WARNING: Missing exception handler attribute for start block: B:3:0x0017 */
        /* JADX WARNING: Missing exception handler attribute for start block: B:5:0x0022 */
        static {
            /*
                r0 = 24199(0x5e87, float:3.391E-41)
                com.bytedance.covode.number.Covode.recordClassIndex(r0)
                com.bytedance.bae.base.Logging$Severity[] r0 = com.bytedance.bae.base.Logging.Severity.values()
                int r0 = r0.length
                int[] r2 = new int[r0]
                $SwitchMap$com$bytedance$bae$base$Logging$Severity = r2
                com.bytedance.bae.base.Logging$Severity r0 = com.bytedance.bae.base.Logging.Severity.LS_ERROR     // Catch:{ NoSuchFieldError -> 0x0017 }
                int r1 = r0.ordinal()     // Catch:{ NoSuchFieldError -> 0x0017 }
                r0 = 1
                r2[r1] = r0     // Catch:{ NoSuchFieldError -> 0x0017 }
            L_0x0017:
                int[] r2 = $SwitchMap$com$bytedance$bae$base$Logging$Severity     // Catch:{ NoSuchFieldError -> 0x0022 }
                com.bytedance.bae.base.Logging$Severity r0 = com.bytedance.bae.base.Logging.Severity.LS_WARNING     // Catch:{ NoSuchFieldError -> 0x0022 }
                int r1 = r0.ordinal()     // Catch:{ NoSuchFieldError -> 0x0022 }
                r0 = 2
                r2[r1] = r0     // Catch:{ NoSuchFieldError -> 0x0022 }
            L_0x0022:
                int[] r2 = $SwitchMap$com$bytedance$bae$base$Logging$Severity     // Catch:{ NoSuchFieldError -> 0x002d }
                com.bytedance.bae.base.Logging$Severity r0 = com.bytedance.bae.base.Logging.Severity.LS_INFO     // Catch:{ NoSuchFieldError -> 0x002d }
                int r1 = r0.ordinal()     // Catch:{ NoSuchFieldError -> 0x002d }
                r0 = 3
                r2[r1] = r0     // Catch:{ NoSuchFieldError -> 0x002d }
            L_0x002d:
                return
            */
            throw new UnsupportedOperationException("Method not decompiled: com.bytedance.bae.base.Logging.AnonymousClass1.<clinit>():void");
        }
    }

    public static String getStackTraceString(Throwable th) {
        if (th == null) {
            return "";
        }
        StringWriter stringWriter = new StringWriter();
        th.printStackTrace(new PrintWriter(stringWriter));
        return stringWriter.toString();
    }

    public static synchronized void enableLogToDebugOutput(Severity severity) {
        synchronized (Logging.class) {
            MethodCollector.i(16846);
            if (loggable == null) {
                nativeEnableLogToDebugOutput(severity.ordinal());
                loggingEnabled = true;
                MethodCollector.o(16846);
            } else {
                IllegalStateException illegalStateException = new IllegalStateException("Logging to native debug output not supported while Loggable is injected. Delete the Loggable before calling this method.");
                MethodCollector.o(16846);
                throw illegalStateException;
            }
        }
    }

    public static void d(String str, String str2) {
        log(Severity.LS_DEBUG, str, str2);
    }

    public static void e(String str, String str2) {
        log(Severity.LS_ERROR, str, str2);
    }

    public static void i(String str, String str2) {
        log(Severity.LS_INFO, str, str2);
    }

    public static void injectLoggable(Loggable loggable2, Severity severity) {
        if (loggable2 != null) {
            loggable = loggable2;
            loggableSeverity = severity;
        }
    }

    public static void t(String str, String str2) {
        log(Severity.LS_TRACE, str, str2);
    }

    public static void w(String str, String str2) {
        log(Severity.LS_WARNING, str, str2);
    }

    public static void e(String str, String str2, Throwable th) {
        log(Severity.LS_ERROR, str, str2);
        log(Severity.LS_ERROR, str, th.toString());
        log(Severity.LS_ERROR, str, getStackTraceString(th));
    }

    public static void w(String str, String str2, Throwable th) {
        log(Severity.LS_WARNING, str, str2);
        log(Severity.LS_WARNING, str, th.toString());
        log(Severity.LS_WARNING, str, getStackTraceString(th));
    }

    public static void log(Severity severity, String str, String str2) {
        Level level;
        MethodCollector.i(16957);
        if (str == null || str2 == null) {
            IllegalArgumentException illegalArgumentException = new IllegalArgumentException("Logging tag or message may not be null.");
            MethodCollector.o(16957);
            throw illegalArgumentException;
        } else if (loggable != null) {
            if (severity.ordinal() < loggableSeverity.ordinal()) {
                MethodCollector.o(16957);
                return;
            }
            loggable.onLogMessage(str2, severity, str);
            MethodCollector.o(16957);
        } else if (loggingEnabled) {
            nativeLog(severity.ordinal(), str, str2);
            MethodCollector.o(16957);
        } else {
            int i = AnonymousClass1.$SwitchMap$com$bytedance$bae$base$Logging$Severity[severity.ordinal()];
            if (i == 1) {
                level = Level.SEVERE;
            } else if (i == 2) {
                level = Level.WARNING;
            } else if (i != 3) {
                level = Level.FINE;
            } else {
                level = Level.INFO;
            }
            Logger logger = fallbackLogger;
            logger.log(level, str + ": " + str2);
            MethodCollector.o(16957);
        }
    }
}
