001    /*******************************************************************************
002     * Portions created by Sebastian Thomschke are copyright (c) 2005-2011 Sebastian
003     * Thomschke.
004     * 
005     * All Rights Reserved. This program and the accompanying materials
006     * are made available under the terms of the Eclipse Public License v1.0
007     * which accompanies this distribution, and is available at
008     * http://www.eclipse.org/legal/epl-v10.html
009     * 
010     * Contributors:
011     *     Sebastian Thomschke - initial implementation.
012     *******************************************************************************/
013    package net.sf.oval.logging;
014    
015    import net.sf.oval.internal.util.Assert;
016    
017    import org.apache.log4j.Level;
018    
019    /**
020     * Log4J Wrapper
021     * @author Sebastian Thomschke
022     */
023    public class LoggerL4JImpl implements Logger
024    {
025            private static final String WRAPPER = "net.sf.oval.logging";
026    
027            private final org.apache.log4j.Logger log4jLogger;
028    
029            /**
030             * @param name the name of the logger
031             * @throws IllegalArgumentException if <code>name == null</code>
032             */
033            public LoggerL4JImpl(final String name) throws IllegalArgumentException
034            {
035                    Assert.argumentNotNull("name", name);
036                    log4jLogger = org.apache.log4j.Logger.getLogger(name);
037            }
038    
039            /**
040             * {@inheritDoc}
041             */
042            public void debug(final String msg)
043            {
044                    log4jLogger.log(WRAPPER, Level.DEBUG, msg, null);
045            }
046    
047            /**
048             * {@inheritDoc}
049             */
050            public void debug(final String msg, final Throwable t)
051            {
052                    log4jLogger.log(WRAPPER, Level.DEBUG, msg, t);
053            }
054    
055            /**
056             * {@inheritDoc}
057             */
058            public void error(final String msg)
059            {
060                    log4jLogger.log(WRAPPER, Level.ERROR, msg, null);
061            }
062    
063            /**
064             * {@inheritDoc}
065             */
066            public void error(final String msg, final Throwable t)
067            {
068                    log4jLogger.log(WRAPPER, Level.ERROR, msg, t);
069            }
070    
071            /**
072             * {@inheritDoc}
073             */
074            public void info(final String msg)
075            {
076                    log4jLogger.log(WRAPPER, Level.INFO, msg, null);
077            }
078    
079            /**
080             * {@inheritDoc}
081             */
082            public void info(final String msg, final Throwable t)
083            {
084                    log4jLogger.log(WRAPPER, Level.INFO, msg, t);
085            }
086    
087            /**
088             * {@inheritDoc}
089             */
090            public boolean isDebug()
091            {
092                    return log4jLogger.isDebugEnabled();
093            }
094    
095            /**
096             * {@inheritDoc}
097             */
098            public boolean isError()
099            {
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    }