View Javadoc

1   /*
2    *  soapUI, copyright (C) 2006 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of the GNU Lesser General Public License as published by the Free Software Foundation; 
6    *  either version 2.1 of the License, or (at your option) any later version.
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  public class JettyLogger implements Logger
19  {
20  	org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger( "jetty" );
21  	
22  	public void debug( String arg0, Throwable arg1 )
23  	{
24  		log.debug( arg0, arg1 );
25  	}
26  
27  	public void debug( String arg0, Object arg1, Object arg2 )
28  	{
29  		log.debug( format( arg0, arg1, arg2 ) );
30  	}
31  
32  	public Logger getLogger( String arg0 )
33  	{
34  		System.out.println( "Ignoring request for logger [" + arg0 + "]" );
35  		return this;
36  	}
37  
38  	public void info( String arg0, Object arg1, Object arg2 )
39  	{
40  		log.info( format( arg0, arg1, arg2 ) );
41  	}
42  
43  	public boolean isDebugEnabled()
44  	{
45  		return log.isDebugEnabled();
46  	}
47  
48  	public void setDebugEnabled( boolean arg0 )
49  	{
50  		log.setLevel( Level.DEBUG );
51  	}
52  
53  	public void warn( String arg0, Throwable arg1 )
54  	{
55  		log.warn(  arg0, arg1 );
56  		
57  	}
58  
59  	public void warn( String arg0, Object arg1, Object arg2 )
60  	{
61  		log.warn( format( arg0, arg1, arg2 ) );
62  	}
63  	
64  	private String format(String msg, Object arg0, Object arg1)
65     {
66         int i0=msg.indexOf("{}");
67         int i1=i0<0?-1:msg.indexOf("{}",i0+2);
68         
69         if (arg1!=null && i1>=0)
70             msg=msg.substring(0,i1)+arg1+msg.substring(i1+2);
71         if (arg0!=null && i0>=0)
72             msg=msg.substring(0,i0)+arg0+msg.substring(i0+2);
73         return msg;
74     }
75  }