View Javadoc

    1   /*
    2    *  soapUI, copyright (C) 2004-2007 eviware.com
    3    *
    4    *  soapUI is free software; you can redistribute it and/or modify it under the
    5    *  terms of version 2.1 of the GNU Lesser General Public License as published by
    6    *  the Free Software Foundation.
    7    *
    8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
    9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    10   *  See the GNU Lesser General Public License for more details at gnu.org.
    11   */
    12
    13  package com.eviware.soapui.support.log;
    14
    15  import java.util.HashSet;
    16  import java.util.Set;
    17
    18  import org.apache.log4j.Level;
    19  import org.apache.log4j.Logger;
    20
    21  import com.eviware.soapui.SoapUI;
    22  import com.eviware.soapui.model.testsuite.LoadTestRunner;
    23  import com.eviware.soapui.monitor.support.TestMonitorListenerAdapter;
    24  import com.eviware.soapui.settings.UISettings;
    25
    26  /***
    27   * Disables httpclient and groovy logs during loadtests
    28   *
    29   * @author ole
    30   */
    31
    32  public final class LogDisablingTestMonitorListener extends TestMonitorListenerAdapter
    33  {
    34  	private Set<LoadTestRunner> loadTestRunners = new HashSet<LoadTestRunner>();
    35
    36  	public void loadTestStarted(LoadTestRunner runner)
    37  	{
    38  		if( loadTestRunners.isEmpty() )
    39  		{
    40  			Logger.getLogger( SoapUI.class ).info( "Disabling logs during loadtests" );
    41  			Logger.getLogger( "httpclient.wire" ).setLevel( Level.OFF );
    42
    43  			if( !SoapUI.getSettings().getBoolean( UISettings.DONT_DISABLE_GROOVY_LOG ))
    44  				Logger.getLogger( "groovy.log" ).setLevel( Level.OFF );
    45  		}
    46
    47  		loadTestRunners.add( runner );
    48  	}
    49
    50  	public void loadTestFinished(LoadTestRunner runner)
    51  	{
    52  		loadTestRunners.remove( runner );
    53
    54  		if( loadTestRunners.isEmpty() )
    55  		{
    56  			Logger.getLogger( "httpclient.wire" ).setLevel( Level.DEBUG );
    57  			Logger.getLogger( "groovy.log" ).setLevel( Level.DEBUG );
    58  			Logger.getLogger( SoapUI.class ).info( "Enabled logs after loadtests" );
    59  		}
    60  	}
    61  }