001// SECTION-START[License Header]
002// <editor-fold defaultstate="collapsed" desc=" Generated License ">
003/*
004 *   Java Object Management and Configuration
005 *   Copyright (C) Christian Schulte, 2005-206
006 *   All rights reserved.
007 *
008 *   Redistribution and use in source and binary forms, with or without
009 *   modification, are permitted provided that the following conditions
010 *   are met:
011 *
012 *     o Redistributions of source code must retain the above copyright
013 *       notice, this list of conditions and the following disclaimer.
014 *
015 *     o Redistributions in binary form must reproduce the above copyright
016 *       notice, this list of conditions and the following disclaimer in
017 *       the documentation and/or other materials provided with the
018 *       distribution.
019 *
020 *   THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
021 *   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
022 *   AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
023 *   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
024 *   INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
025 *   NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
026 *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
027 *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
028 *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
029 *   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
030 *
031 *   $JOMC$
032 *
033 */
034// </editor-fold>
035// SECTION-END
036package org.jomc.logging.ri.log4j;
037
038import java.util.logging.Level;
039
040// SECTION-START[Documentation]
041// <editor-fold defaultstate="collapsed" desc=" Generated Documentation ">
042/**
043 * Object management and configuration logging system implementation backed by Log4J.
044 *
045 * <dl>
046 *   <dt><b>Identifier:</b></dt><dd>org.jomc.logging.ri.log4j.Log4JLogger</dd>
047 *   <dt><b>Name:</b></dt><dd>JOMC Logging ⁑ Log4J Logging</dd>
048 *   <dt><b>Specifications:</b></dt>
049 *     <dd>org.jomc.logging.Logger @ 1.1</dd>
050 *     <dd>org.jomc.spi.Listener @ 1.0</dd>
051 *   <dt><b>Abstract:</b></dt><dd>No</dd>
052 *   <dt><b>Final:</b></dt><dd>No</dd>
053 *   <dt><b>Stateless:</b></dt><dd>Yes</dd>
054 * </dl>
055 *
056 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a> 1.0
057 * @version 1.3
058 */
059// </editor-fold>
060// SECTION-END
061// SECTION-START[Annotations]
062// <editor-fold defaultstate="collapsed" desc=" Generated Annotations ">
063@javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.5", comments = "See http://www.jomc.org/jomc/1.5/jomc-tools-1.5" )
064// </editor-fold>
065// SECTION-END
066public final class Log4JLogger
067    implements org.jomc.logging.Logger,
068               org.jomc.spi.Listener
069{
070    // SECTION-START[Constructors]
071    // <editor-fold defaultstate="collapsed" desc=" Generated Constructors ">
072    /** Creates a new {@code Log4JLogger} instance. */
073    @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.5", comments = "See http://www.jomc.org/jomc/1.5/jomc-tools-1.5" )
074    public Log4JLogger()
075    {
076        // SECTION-START[Default Constructor]
077        super();
078        // SECTION-END
079    }
080    // </editor-fold>
081    // SECTION-END
082    // SECTION-START[Logger]
083
084    public boolean isConfigEnabled()
085    {
086        return this.getLogger().isEnabledFor( org.apache.log4j.Level.DEBUG );
087    }
088
089    public void config( final String string )
090    {
091        this.getLogger().debug( string );
092    }
093
094    public void config( final Throwable throwable )
095    {
096        this.getLogger().debug( throwable.getMessage(), throwable );
097    }
098
099    public void config( final String message, final Throwable throwable )
100    {
101        this.getLogger().debug( message, throwable );
102    }
103
104    public boolean isDebugEnabled()
105    {
106        return this.getLogger().isEnabledFor( org.apache.log4j.Level.DEBUG );
107    }
108
109    public void debug( final String string )
110    {
111        this.getLogger().debug( string );
112    }
113
114    public void debug( final Throwable throwable )
115    {
116        this.getLogger().debug( throwable.getMessage(), throwable );
117    }
118
119    public void debug( final String message, final Throwable throwable )
120    {
121        this.getLogger().debug( message, throwable );
122    }
123
124    public boolean isErrorEnabled()
125    {
126        return this.getLogger().isEnabledFor( org.apache.log4j.Level.ERROR );
127    }
128
129    public void error( final String string )
130    {
131        this.getLogger().error( string );
132    }
133
134    public void error( final Throwable throwable )
135    {
136        this.getLogger().error( throwable.getMessage(), throwable );
137    }
138
139    public void error( final String message, final Throwable throwable )
140    {
141        this.getLogger().error( message, throwable );
142    }
143
144    public boolean isFatalEnabled()
145    {
146        return this.getLogger().isEnabledFor( org.apache.log4j.Level.FATAL );
147    }
148
149    public void fatal( final String string )
150    {
151        this.getLogger().fatal( string );
152    }
153
154    public void fatal( final Throwable throwable )
155    {
156        this.getLogger().fatal( throwable.getMessage(), throwable );
157    }
158
159    public void fatal( final String message, final Throwable throwable )
160    {
161        this.getLogger().fatal( message, throwable );
162    }
163
164    public boolean isInfoEnabled()
165    {
166        return this.getLogger().isEnabledFor( org.apache.log4j.Level.INFO );
167    }
168
169    public void info( final String string )
170    {
171        this.getLogger().info( string );
172    }
173
174    public void info( final Throwable throwable )
175    {
176        this.getLogger().info( throwable.getMessage(), throwable );
177    }
178
179    public void info( final String message, final Throwable throwable )
180    {
181        this.getLogger().info( message, throwable );
182    }
183
184    public boolean isTraceEnabled()
185    {
186        return this.getLogger().isEnabledFor( org.apache.log4j.Level.TRACE );
187    }
188
189    public void trace( final String string )
190    {
191        this.getLogger().trace( string );
192    }
193
194    public void trace( final Throwable throwable )
195    {
196        this.getLogger().trace( throwable.getMessage(), throwable );
197    }
198
199    public void trace( final String message, final Throwable throwable )
200    {
201        this.getLogger().trace( message, throwable );
202    }
203
204    public boolean isWarnEnabled()
205    {
206        return this.getLogger().isEnabledFor( org.apache.log4j.Level.WARN );
207    }
208
209    public void warn( final String string )
210    {
211        this.getLogger().warn( string );
212    }
213
214    public void warn( final Throwable throwable )
215    {
216        this.getLogger().warn( throwable.getMessage(), throwable );
217    }
218
219    public void warn( final String message, final Throwable throwable )
220    {
221        this.getLogger().warn( message, throwable );
222    }
223
224    // SECTION-END
225    // SECTION-START[Listener]
226    public void onLog( final Level level, final String message, final Throwable throwable )
227    {
228        if ( level != null )
229        {
230            if ( level.intValue() <= Level.FINEST.intValue() )
231            {
232                this.getObjectManagementLogger().trace( message, throwable );
233            }
234            else if ( level.intValue() <= Level.FINER.intValue() )
235            {
236                this.getObjectManagementLogger().debug( message, throwable );
237            }
238            else if ( level.intValue() <= Level.FINE.intValue() )
239            {
240                this.getObjectManagementLogger().debug( message, throwable );
241            }
242            else if ( level.intValue() <= Level.CONFIG.intValue() )
243            {
244                this.getObjectManagementLogger().config( message, throwable );
245            }
246            else if ( level.intValue() <= Level.INFO.intValue() )
247            {
248                this.getObjectManagementLogger().info( message, throwable );
249            }
250            else if ( level.intValue() <= Level.WARNING.intValue() )
251            {
252                this.getObjectManagementLogger().warn( message, throwable );
253            }
254            else if ( level.intValue() <= Level.SEVERE.intValue() )
255            {
256                this.getObjectManagementLogger().error( message, throwable );
257            }
258            else if ( level.intValue() < Level.OFF.intValue() )
259            {
260                this.getObjectManagementLogger().fatal( message, throwable );
261            }
262        }
263    }
264    // SECTION-END
265    // SECTION-START[Log4JLogger]
266
267    /**
268     * Gets the Log4J logger backing the instance.
269     *
270     * @return The Log4J logger backing the instance.
271     *
272     * @see #getName()
273     * @see org.apache.log4j.Logger#getLogger(java.lang.String)
274     */
275    public org.apache.log4j.Logger getLogger()
276    {
277        return org.apache.log4j.Logger.getLogger( this.getName() );
278    }
279
280    // SECTION-END
281    // SECTION-START[Dependencies]
282    // <editor-fold defaultstate="collapsed" desc=" Generated Dependencies ">
283    /**
284     * Gets the {@code <ObjectManagementLogger>} dependency.
285     * <p>
286     *   This method returns the {@code <JOMC Logging ⁑ Log4J Logging>} object of the {@code <org.jomc.logging.Logger>} specification at specification level 1.1.
287     *   That specification does not apply to any scope. A new object is returned whenever requested and bound to this instance.
288     * </p>
289     * <p><strong>Properties:</strong>
290     *   <table border="1" width="100%" cellpadding="3" cellspacing="0">
291     *     <tr class="TableSubHeadingColor">
292     *       <th align="left" scope="col" nowrap><b>Name</b></th>
293     *       <th align="left" scope="col" nowrap><b>Type</b></th>
294     *       <th align="left" scope="col" nowrap><b>Documentation</b></th>
295     *     </tr>
296     *     <tr class="TableRow">
297     *       <td align="left" valign="top" nowrap>{@code <name>}</td>
298     *       <td align="left" valign="top" nowrap>{@code java.lang.String}</td>
299     *       <td align="left" valign="top">Name of the logger object management events are logged with.</td>
300     *     </tr>
301     *   </table>
302     * </p>
303     * <dl>
304     *   <dt><b>Final:</b></dt><dd>No</dd>
305     * </dl>
306     * @return Logger object management events are logged with.
307     * @throws org.jomc.ObjectManagementException if getting the dependency instance fails.
308     */
309    @SuppressWarnings("unused")
310    @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.5", comments = "See http://www.jomc.org/jomc/1.5/jomc-tools-1.5" )
311    private org.jomc.logging.Logger getObjectManagementLogger()
312    {
313        final org.jomc.logging.Logger _d = (org.jomc.logging.Logger) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getDependency( this, "ObjectManagementLogger" );
314        assert _d != null : "'ObjectManagementLogger' dependency not found.";
315        return _d;
316    }
317    // </editor-fold>
318    // SECTION-END
319    // SECTION-START[Properties]
320    // <editor-fold defaultstate="collapsed" desc=" Generated Properties ">
321    /**
322     * Gets the value of the {@code <name>} property.
323     * <p><dl>
324     *   <dt><b>Final:</b></dt><dd>No</dd>
325     * </dl></p>
326     * @return Name of the component events are logged for.
327     * @throws org.jomc.ObjectManagementException if getting the property instance fails.
328     */
329    @SuppressWarnings("unused")
330    @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.5", comments = "See http://www.jomc.org/jomc/1.5/jomc-tools-1.5" )
331    public java.lang.String getName()
332    {
333        final java.lang.String _p = (java.lang.String) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "name" );
334        assert _p != null : "'name' property not found.";
335        return _p;
336    }
337    // </editor-fold>
338    // SECTION-END
339    // SECTION-START[Messages]
340    // SECTION-END
341}