/**
 * Copyright (c) 2013 Linagora
 * 
 * This program/library is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 2.1 of the License, or (at your
 * option) any later version.
 * 
 * This program/library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
 * for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program/library; If not, see <http://www.gnu.org/licenses/>
 * for the GNU Lesser General Public License version 2.1.
 */
package org.ow2.petals.cli.http;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * A jetty logger implementation based on the root logger of the component.
 * @author Christophe Hamerling - EBM WebSourcing
 */
public class JettyLogger implements org.eclipse.jetty.util.log.Logger {

    /**
     * The component logger
     */
    protected Logger logger;
    
    /**
     * Creates a new instance of {@link JettyLogger}
     * 
     * @param name
     * @param logger
     */
    public JettyLogger(final java.util.logging.Logger logger) {
        this.logger = logger;
    }

    @Override
    public void debug(final String arg0, final Object... args) {
        logger.log(Level.FINEST, arg0, new Object[] { args });
    }

    @Override
    public void debug(final String arg0, final Throwable arg1) {
        logger.log(Level.FINEST, arg0, arg1);
    }

    @Override
    public org.eclipse.jetty.util.log.Logger getLogger(final String arg0) {
        return this;
    }

    @Override
    public void info(final String arg0, final Object... args) {
        logger.log(Level.INFO, arg0, new Object[] { args });
    }

    @Override
    public boolean isDebugEnabled() {
        return logger.isLoggable(Level.FINEST);
    }

    @Override
    public void setDebugEnabled(final boolean arg0) {
        logger.setLevel(Level.FINEST);
    }

    @Override
    public void warn(final String arg0, final Object... args) {
        logger.log(Level.WARNING, arg0, new Object[] { args });
    }

    @Override
    public void warn(final String arg0, final Throwable arg1) {
        logger.log(Level.WARNING, arg0, arg1);
    }

    @Override
    public String getName() {
        return logger.getName();
    }

    @Override
    public void warn(final Throwable thrown) {
        this.warn(thrown.getMessage(), thrown);
    }

    @Override
    public void info(final Throwable thrown) {
        this.info(thrown.getMessage(), thrown);
    }

    @Override
    public void info(final String msg, final Throwable thrown) {
        logger.log(Level.INFO, msg, thrown);
    }

    @Override
    public void debug(final Throwable thrown) {
        this.debug(thrown.getMessage(), thrown);
    }

    @Override
    public void ignore(final Throwable ignored) {
        if (this.isDebugEnabled()) {
            this.debug(ignored);
        }
    }
}
