/*-
 * Copyright (c) 2016 Red Hat, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.fedoraproject.xmvn.logging.impl;

import org.codehaus.plexus.component.annotations.Component;
import org.slf4j.LoggerFactory;

/**
 * @author Mikolaj Izdebski
 */
@Component( role = Logger.class )
public class Slf4jLoggerAdapter
    implements Logger
{
    private final org.slf4j.Logger delegate;

    public Slf4jLoggerAdapter()
    {
        boolean debug = System.getProperty( "xmvn.debug" ) != null;

        if ( debug )
            System.setProperty( "org.slf4j.simpleLogger.log.XMvn", "trace" );

        delegate = LoggerFactory.getLogger( "XMvn" );
    }

    @Override
    public boolean isDebugEnabled()
    {
        return delegate.isDebugEnabled();
    }

    @Override
    public void debug( String format, Object... args )
    {
        delegate.debug( format, args );
    }

    @Override
    public void info( String format, Object... args )
    {
        delegate.info( format, args );
    }

    @Override
    public void warn( String format, Object... args )
    {
        delegate.warn( format, args );
    }

    @Override
    public void error( String format, Object... args )
    {
        delegate.error( format, args );
    }
}

@@ -641,16 +641,50 @@
 .impl;%0A%0A
+import java.lang.reflect.Method;%0A%0A
 import o
@@ -735,16 +735,16 @@
 ponent;%0A
-
 import o
@@ -800,20 +800,43 @@
 zdebski%0A
+ * @author Roman Vais%0A
  */%0A
+%0A
 @Compone
@@ -1170,16 +1170,16 @@
 ce%22 );%0A%0A
-
         
@@ -1223,16 +1223,952 @@
 XMvn%22 );
+%0A%0A        try%0A        %7B%0A            Class%3C?%3E gossipLogClass = Class.forName( %22com.planet57.gossip.Gossip$LoggerImpl%22 );%0A            boolean isGossipLogger = gossipLogClass.isAssignableFrom( delegate.getClass() );%0A%0A            try%0A            %7B%0A                if ( isGossipLogger && debug )%0A                %7B%0A                    Class%3C?%3E levelClass = Class.forName( %22com.planet57.gossip.Level%22 );%0A                    Method setLogLevel = delegate.getClass().getMethod( %22setLevel%22, levelClass );%0A%0A                    Object lvl = levelClass.getField( %22ALL%22 ).get( levelClass );%0A%0A                    setLogLevel.invoke( delegate, lvl );%0A                %7D%0A%0A            %7D%0A            catch ( ReflectiveOperationException e )%0A            %7B%0A                delegate.error( %22Unable to set logging level to 'debug' for Gossip logger implementation.%22, e );%0A            %7D%0A        %7D%0A        catch ( ClassNotFoundException ex )%0A        %7B%0A%0A        %7D
 %0A    %7D%0A%0A

Add debug level seting for gossip into Slf4jLoggerAdapter