All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.slf4j.impl.MufferoLoggerAdapter Maven / Gradle / Ivy

There is a newer version: 2.1.0
Show newest version
package org.slf4j.impl;

import net.rumati.logging.muffero.Priority;
import net.rumati.logging.muffero.Logger;
import org.slf4j.Marker;
import org.slf4j.helpers.FormattingTuple;
import org.slf4j.helpers.MarkerIgnoringBase;
import org.slf4j.helpers.MessageFormatter;
import org.slf4j.spi.LocationAwareLogger;

class MufferoLoggerAdapter
        extends MarkerIgnoringBase
        implements LocationAwareLogger
{
    private static final String FQCN = MufferoLoggerAdapter.class.getName();
    private final Logger log;

    public MufferoLoggerAdapter(Logger log)
    {
        this.log = log;
    }

    public boolean isTraceEnabled()
    {
        return log.isTraceEnabled();
    }

    public void trace(String msg)
    {
        trace(msg, new Object[]{});
    }

    public void trace(String format, Object arg)
    {
        trace(format, new Object[]{arg});
    }

    public void trace(String format, Object arg1, Object arg2)
    {
        trace(format, new Object[]{arg1, arg2});
    }

    public void trace(String format, Object[] argArray)
    {
        log(FQCN, Priority.TRACE, format, argArray, null);
    }

    public void trace(String msg, Throwable t)
    {
        log(FQCN, Priority.TRACE, msg, new Object[]{}, t);
    }

    public boolean isDebugEnabled()
    {
        return log.isDebugEnabled();
    }

    public void debug(String msg)
    {
        debug(msg, new Object[]{});
    }

    public void debug(String format, Object arg)
    {
        debug(format, new Object[]{arg});
    }

    public void debug(String format, Object arg1, Object arg2)
    {
        debug(format, new Object[]{arg1, arg2});
    }

    public void debug(String format, Object[] argArray)
    {
        log(FQCN, Priority.DEBUG, format, argArray, null);
    }

    public void debug(String msg, Throwable t)
    {
        log(FQCN, Priority.DEBUG, msg, new Object[]{}, t);
    }

    public boolean isInfoEnabled()
    {
        return log.isInfoEnabled();
    }

    public void info(String msg)
    {
        info(msg, new Object[]{});
    }

    public void info(String format, Object arg)
    {
        info(format, new Object[]{arg});
    }

    public void info(String format, Object arg1, Object arg2)
    {
        info(format, new Object[]{arg1, arg2});
    }

    public void info(String format, Object[] argArray)
    {
        log(FQCN, Priority.INFO, format, argArray, null);
    }

    public void info(String msg, Throwable t)
    {
        log(FQCN, Priority.INFO, msg, new Object[]{}, t);
    }

    public boolean isWarnEnabled()
    {
        return log.isWarnEnabled();
    }

    public void warn(String msg)
    {
        warn(msg, new Object[]{});
    }

    public void warn(String format, Object arg)
    {
        warn(format, new Object[]{arg});
    }

    public void warn(String format, Object arg1, Object arg2)
    {
        warn(format, new Object[]{arg1, arg2});
    }

    public void warn(String format, Object[] argArray)
    {
        log(FQCN, Priority.WARNING, format, argArray, null);
    }

    public void warn(String msg, Throwable t)
    {
        log(FQCN, Priority.WARNING, msg, new Object[]{}, t);
    }

    public boolean isErrorEnabled()
    {
        return log.isErrorEnabled();
    }

    public void error(String msg)
    {
        error(msg, new Object[]{});
    }

    public void error(String format, Object arg)
    {
        error(format, new Object[]{arg});
    }

    public void error(String format, Object arg1, Object arg2)
    {
        error(format, new Object[]{arg1, arg2});
    }

    public void error(String format, Object[] argArray)
    {
        log(FQCN, Priority.ERROR, format, argArray, null);
    }

    public void error(String msg, Throwable t)
    {
        log(FQCN, Priority.ERROR, msg, new Object[]{}, t);
    }

    private void log(String fqcn, Priority level, String message, Object[] argArray, Throwable t)
    {
        if (argArray == null || argArray.length == 0){
            log.log(level, fqcn, message, t);
        }else{
            FormattingTuple ft = MessageFormatter.arrayFormat(message, argArray);
            if (t == null){
                t = ft.getThrowable();
            }
            log.log(level, fqcn, ft.getMessage(), t);
        }
    }

    public void log(Marker marker, String fqcn, int level, String message, Object[] argArray, Throwable t)
    {
        Priority l = null;
        switch (level){
            case LocationAwareLogger.TRACE_INT:
                l = Priority.TRACE;
                break;
            case LocationAwareLogger.DEBUG_INT:
                l = Priority.DEBUG;
                break;
            case LocationAwareLogger.INFO_INT:
                l = Priority.INFO;
                break;
            case LocationAwareLogger.WARN_INT:
                l = Priority.WARNING;
                break;
            case LocationAwareLogger.ERROR_INT:
                l = Priority.ERROR;
                break;
            default:
                throw new UnsupportedOperationException("Unknown logger level: " + level);
        }
        log(fqcn, l, message, argArray, t);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy