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 org.apache.log4j.Level;
    16  import org.mortbay.log.Logger;
    17
    18  /***
    19   * Logger for Jetty Events
    20   *
    21   * @author ole.matzura
    22   */
    23
    24  public class JettyLogger implements Logger
    25  {
    26  	org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger( "jetty" );
    27
    28  	public void debug( String arg0, Throwable arg1 )
    29  	{
    30  		log.debug( arg0, arg1 );
    31  	}
    32
    33  	public void debug( String arg0, Object arg1, Object arg2 )
    34  	{
    35  		log.debug( format( arg0, arg1, arg2 ) );
    36  	}
    37
    38  	public Logger getLogger( String arg0 )
    39  	{
    40  		System.out.println( "Ignoring request for logger [" + arg0 + "]" );
    41  		return this;
    42  	}
    43
    44  	public void info( String arg0, Object arg1, Object arg2 )
    45  	{
    46  		log.info( format( arg0, arg1, arg2 ) );
    47  	}
    48
    49  	public boolean isDebugEnabled()
    50  	{
    51  		return log.isDebugEnabled();
    52  	}
    53
    54  	public void setDebugEnabled( boolean arg0 )
    55  	{
    56  		log.setLevel( Level.DEBUG );
    57  	}
    58
    59  	public void warn( String arg0, Throwable arg1 )
    60  	{
    61  		log.warn(  arg0, arg1 );
    62
    63  	}
    64
    65  	public void warn( String arg0, Object arg1, Object arg2 )
    66  	{
    67  		log.warn( format( arg0, arg1, arg2 ) );
    68  	}
    69
    70  	private String format(String msg, Object arg0, Object arg1)
    71     {
    72         int i0=msg.indexOf("{}");
    73         int i1=i0<0?-1:msg.indexOf("{}",i0+2);
    74
    75         if (arg1!=null && i1>=0)
    76             msg=msg.substring(0,i1)+arg1+msg.substring(i1+2);
    77         if (arg0!=null && i0>=0)
    78             msg=msg.substring(0,i0)+arg0+msg.substring(i0+2);
    79         return msg;
    80     }
    81  }