// 
// Decompiled by Procyon v0.6.0
// 

package com.google.common.flogger.backend.system;

import com.google.common.flogger.util.StackBasedLogSite;
import com.google.common.flogger.LogSite;
import com.google.common.flogger.util.CallerFinder;
import com.google.common.flogger.AbstractLogger;
import com.google.common.flogger.backend.Platform;

public final class StackBasedCallerFinder extends Platform.LogCallerFinder
{
    private static final Platform.LogCallerFinder INSTANCE;
    
    public static Platform.LogCallerFinder getInstance() {
        return StackBasedCallerFinder.INSTANCE;
    }
    
    @Override
    public String findLoggingClass(final Class<? extends AbstractLogger<?>> loggerClass) {
        final StackTraceElement caller = CallerFinder.findCallerOf(loggerClass, new Throwable(), 1);
        if (caller != null) {
            return caller.getClassName();
        }
        throw new IllegalStateException("no caller found on the stack for: " + loggerClass.getName());
    }
    
    @Override
    public LogSite findLogSite(final Class<?> loggerApi, final int stackFramesToSkip) {
        final StackTraceElement caller = CallerFinder.findCallerOf(loggerApi, new Throwable(), stackFramesToSkip + 1);
        return (caller != null) ? new StackBasedLogSite(caller) : LogSite.INVALID;
    }
    
    @Override
    public String toString() {
        return "Default stack-based caller finder";
    }
    
    private StackBasedCallerFinder() {
    }
    
    static {
        INSTANCE = new StackBasedCallerFinder();
    }
}
