View Javadoc
1   /*******************************************************************************
2    * Portions created by Sebastian Thomschke are copyright (c) 2005-2011 Sebastian
3    * Thomschke.
4    * 
5    * All Rights Reserved. This program and the accompanying materials
6    * are made available under the terms of the Eclipse Public License v1.0
7    * which accompanies this distribution, and is available at
8    * http://www.eclipse.org/legal/epl-v10.html
9    * 
10   * Contributors:
11   *     Sebastian Thomschke - initial implementation.
12   *******************************************************************************/
13  package net.sf.oval.logging;
14  
15  import net.sf.oval.internal.util.Assert;
16  
17  import org.apache.log4j.Level;
18  
19  /**
20   * Log4J Wrapper
21   * @author Sebastian Thomschke
22   */
23  public class LoggerL4JImpl implements Logger
24  {
25  	private static final String WRAPPER = "net.sf.oval.logging";
26  
27  	private final org.apache.log4j.Logger log4jLogger;
28  
29  	/**
30  	 * @param name the name of the logger
31  	 * @throws IllegalArgumentException if <code>name == null</code>
32  	 */
33  	public LoggerL4JImpl(final String name) throws IllegalArgumentException
34  	{
35  		Assert.argumentNotNull("name", name);
36  		log4jLogger = org.apache.log4j.Logger.getLogger(name);
37  	}
38  
39  	/**
40  	 * {@inheritDoc}
41  	 */
42  	public void debug(final String msg)
43  	{
44  		log4jLogger.log(WRAPPER, Level.DEBUG, msg, null);
45  	}
46  
47  	/**
48  	 * {@inheritDoc}
49  	 */
50  	public void debug(final String msg, final Throwable t)
51  	{
52  		log4jLogger.log(WRAPPER, Level.DEBUG, msg, t);
53  	}
54  
55  	/**
56  	 * {@inheritDoc}
57  	 */
58  	public void error(final String msg)
59  	{
60  		log4jLogger.log(WRAPPER, Level.ERROR, msg, null);
61  	}
62  
63  	/**
64  	 * {@inheritDoc}
65  	 */
66  	public void error(final String msg, final Throwable t)
67  	{
68  		log4jLogger.log(WRAPPER, Level.ERROR, msg, t);
69  	}
70  
71  	/**
72  	 * {@inheritDoc}
73  	 */
74  	public void info(final String msg)
75  	{
76  		log4jLogger.log(WRAPPER, Level.INFO, msg, null);
77  	}
78  
79  	/**
80  	 * {@inheritDoc}
81  	 */
82  	public void info(final String msg, final Throwable t)
83  	{
84  		log4jLogger.log(WRAPPER, Level.INFO, msg, t);
85  	}
86  
87  	/**
88  	 * {@inheritDoc}
89  	 */
90  	public boolean isDebug()
91  	{
92  		return log4jLogger.isDebugEnabled();
93  	}
94  
95  	/**
96  	 * {@inheritDoc}
97  	 */
98  	public boolean isError()
99  	{
100 		return log4jLogger.isEnabledFor(Level.ERROR);
101 	}
102 
103 	/**
104 	 * {@inheritDoc}
105 	 */
106 	public boolean isInfo()
107 	{
108 		return log4jLogger.isInfoEnabled();
109 	}
110 
111 	/**
112 	 * {@inheritDoc}
113 	 */
114 	public boolean isTrace()
115 	{
116 		return log4jLogger.isTraceEnabled();
117 	}
118 
119 	/**
120 	 * {@inheritDoc}
121 	 */
122 	public boolean isWarn()
123 	{
124 		return log4jLogger.isEnabledFor(Level.WARN);
125 	}
126 
127 	/**
128 	 * {@inheritDoc}
129 	 */
130 	public void trace(final String msg)
131 	{
132 		log4jLogger.log(WRAPPER, Level.TRACE, msg, null);
133 	}
134 
135 	/**
136 	 * {@inheritDoc}
137 	 */
138 	public void trace(final String msg, final Throwable t)
139 	{
140 		log4jLogger.log(WRAPPER, Level.TRACE, msg, t);
141 	}
142 
143 	/**
144 	 * {@inheritDoc}
145 	 */
146 	public void warn(final String msg)
147 	{
148 		log4jLogger.log(WRAPPER, Level.WARN, msg, null);
149 	}
150 
151 	/**
152 	 * {@inheritDoc}
153 	 */
154 	public void warn(final String msg, final Throwable t)
155 	{
156 		log4jLogger.log(WRAPPER, Level.WARN, msg, t);
157 	}
158 }