View Javadoc

1   // SECTION-START[License Header]
2   // <editor-fold defaultstate="collapsed" desc=" Generated License ">
3   /*
4    *   Java Object Management and Configuration
5    *   Copyright (C) Christian Schulte, 2005-206
6    *   All rights reserved.
7    *
8    *   Redistribution and use in source and binary forms, with or without
9    *   modification, are permitted provided that the following conditions
10   *   are met:
11   *
12   *     o Redistributions of source code must retain the above copyright
13   *       notice, this list of conditions and the following disclaimer.
14   *
15   *     o Redistributions in binary form must reproduce the above copyright
16   *       notice, this list of conditions and the following disclaimer in
17   *       the documentation and/or other materials provided with the
18   *       distribution.
19   *
20   *   THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
21   *   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22   *   AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
23   *   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
24   *   INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25   *   NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26   *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27   *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28   *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29   *   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30   *
31   *   $JOMC$
32   *
33   */
34  // </editor-fold>
35  // SECTION-END
36  package org.jomc.logging.ri.log4j;
37  
38  import java.util.logging.Level;
39  
40  // SECTION-START[Documentation]
41  // <editor-fold defaultstate="collapsed" desc=" Generated Documentation ">
42  /**
43   * Object management and configuration logging system implementation backed by Log4J.
44   *
45   * <dl>
46   *   <dt><b>Identifier:</b></dt><dd>org.jomc.logging.ri.log4j.Log4JLogger</dd>
47   *   <dt><b>Name:</b></dt><dd>JOMC Logging ⁑ Log4J Logging</dd>
48   *   <dt><b>Specifications:</b></dt>
49   *     <dd>org.jomc.logging.Logger @ 1.1</dd>
50   *     <dd>org.jomc.spi.Listener @ 1.0</dd>
51   *   <dt><b>Abstract:</b></dt><dd>No</dd>
52   *   <dt><b>Final:</b></dt><dd>No</dd>
53   *   <dt><b>Stateless:</b></dt><dd>Yes</dd>
54   * </dl>
55   *
56   * @author <a href="mailto:cs@schulte.it">Christian Schulte</a> 1.0
57   * @version 1.3
58   */
59  // </editor-fold>
60  // SECTION-END
61  // SECTION-START[Annotations]
62  // <editor-fold defaultstate="collapsed" desc=" Generated Annotations ">
63  @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.5", comments = "See http://www.jomc.org/jomc/1.5/jomc-tools-1.5" )
64  // </editor-fold>
65  // SECTION-END
66  public final class Log4JLogger
67      implements org.jomc.logging.Logger,
68                 org.jomc.spi.Listener
69  {
70      // SECTION-START[Constructors]
71      // <editor-fold defaultstate="collapsed" desc=" Generated Constructors ">
72      /** Creates a new {@code Log4JLogger} instance. */
73      @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.5", comments = "See http://www.jomc.org/jomc/1.5/jomc-tools-1.5" )
74      public Log4JLogger()
75      {
76          // SECTION-START[Default Constructor]
77          super();
78          // SECTION-END
79      }
80      // </editor-fold>
81      // SECTION-END
82      // SECTION-START[Logger]
83  
84      public boolean isConfigEnabled()
85      {
86          return this.getLogger().isEnabledFor( org.apache.log4j.Level.DEBUG );
87      }
88  
89      public void config( final String string )
90      {
91          this.getLogger().debug( string );
92      }
93  
94      public void config( final Throwable throwable )
95      {
96          this.getLogger().debug( throwable.getMessage(), throwable );
97      }
98  
99      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 }