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

package com.google.common.flogger;

import com.google.common.flogger.backend.LoggingException;
import com.google.common.flogger.backend.LogData;
import java.util.logging.Level;
import com.google.common.flogger.util.Checks;
import com.google.common.flogger.backend.LoggerBackend;
import com.google.errorprone.annotations.CheckReturnValue;

@CheckReturnValue
public abstract class AbstractLogger<API extends LoggingApi<API>>
{
    private final LoggerBackend backend;
    
    protected AbstractLogger(final LoggerBackend backend) {
        this.backend = Checks.checkNotNull(backend, "backend");
    }
    
    public abstract API at(final Level p0);
    
    public final API atSevere() {
        return this.at(Level.SEVERE);
    }
    
    public final API atWarning() {
        return this.at(Level.WARNING);
    }
    
    public final API atInfo() {
        return this.at(Level.INFO);
    }
    
    public final API atConfig() {
        return this.at(Level.CONFIG);
    }
    
    public final API atFine() {
        return this.at(Level.FINE);
    }
    
    public final API atFiner() {
        return this.at(Level.FINER);
    }
    
    public final API atFinest() {
        return this.at(Level.FINEST);
    }
    
    protected String getName() {
        return this.backend.getLoggerName();
    }
    
    protected final boolean isLoggable(final Level level) {
        return this.backend.isLoggable(level);
    }
    
    final LoggerBackend getBackend() {
        return this.backend;
    }
    
    final void write(final LogData data) {
        Checks.checkNotNull(data, "data");
        try {
            this.backend.log(data);
        }
        catch (final RuntimeException error) {
            try {
                this.backend.handleError(error, data);
            }
            catch (final LoggingException allowed) {
                throw allowed;
            }
            catch (final RuntimeException runtimeException) {
                System.err.println("logging error: " + runtimeException.getMessage());
                runtimeException.printStackTrace(System.err);
            }
        }
    }
}
