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: Log4JLogger.java 4723 2013-01-03 08:50:05Z schulte $ 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.0</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.2 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.4", comments = "See http://www.jomc.org/jomc/1.4/jomc-tools-1.4" ) 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.4", comments = "See http://www.jomc.org/jomc/1.4/jomc-tools-1.4" ) 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 isDebugEnabled() 085 { 086 return this.getLogger().isEnabledFor( org.apache.log4j.Level.DEBUG ); 087 } 088 089 public void debug( final String string ) 090 { 091 this.getLogger().debug( string ); 092 } 093 094 public void debug( final Throwable throwable ) 095 { 096 this.getLogger().debug( throwable.getMessage(), throwable ); 097 } 098 099 public void debug( final String message, final Throwable throwable ) 100 { 101 this.getLogger().debug( message, throwable ); 102 } 103 104 public boolean isErrorEnabled() 105 { 106 return this.getLogger().isEnabledFor( org.apache.log4j.Level.ERROR ); 107 } 108 109 public void error( final String string ) 110 { 111 this.getLogger().error( string ); 112 } 113 114 public void error( final Throwable throwable ) 115 { 116 this.getLogger().error( throwable.getMessage(), throwable ); 117 } 118 119 public void error( final String message, final Throwable throwable ) 120 { 121 this.getLogger().error( message, throwable ); 122 } 123 124 public boolean isFatalEnabled() 125 { 126 return this.getLogger().isEnabledFor( org.apache.log4j.Level.FATAL ); 127 } 128 129 public void fatal( final String string ) 130 { 131 this.getLogger().fatal( string ); 132 } 133 134 public void fatal( final Throwable throwable ) 135 { 136 this.getLogger().fatal( throwable.getMessage(), throwable ); 137 } 138 139 public void fatal( final String message, final Throwable throwable ) 140 { 141 this.getLogger().fatal( message, throwable ); 142 } 143 144 public boolean isInfoEnabled() 145 { 146 return this.getLogger().isEnabledFor( org.apache.log4j.Level.INFO ); 147 } 148 149 public void info( final String string ) 150 { 151 this.getLogger().info( string ); 152 } 153 154 public void info( final Throwable throwable ) 155 { 156 this.getLogger().info( throwable.getMessage(), throwable ); 157 } 158 159 public void info( final String message, final Throwable throwable ) 160 { 161 this.getLogger().info( message, throwable ); 162 } 163 164 public boolean isTraceEnabled() 165 { 166 return this.getLogger().isEnabledFor( org.apache.log4j.Level.TRACE ); 167 } 168 169 public void trace( final String string ) 170 { 171 this.getLogger().trace( string ); 172 } 173 174 public void trace( final Throwable throwable ) 175 { 176 this.getLogger().trace( throwable.getMessage(), throwable ); 177 } 178 179 public void trace( final String message, final Throwable throwable ) 180 { 181 this.getLogger().trace( message, throwable ); 182 } 183 184 public boolean isWarnEnabled() 185 { 186 return this.getLogger().isEnabledFor( org.apache.log4j.Level.WARN ); 187 } 188 189 public void warn( final String string ) 190 { 191 this.getLogger().warn( string ); 192 } 193 194 public void warn( final Throwable throwable ) 195 { 196 this.getLogger().warn( throwable.getMessage(), throwable ); 197 } 198 199 public void warn( final String message, final Throwable throwable ) 200 { 201 this.getLogger().warn( message, throwable ); 202 } 203 204 // SECTION-END 205 // SECTION-START[Listener] 206 public void onLog( final Level level, final String message, final Throwable throwable ) 207 { 208 if ( level != null ) 209 { 210 if ( level.equals( Level.CONFIG ) || level.equals( Level.FINE ) ) 211 { 212 this.getObjectManagementLogger().debug( message, throwable ); 213 } 214 else if ( level.equals( Level.FINER ) || level.equals( Level.FINEST ) ) 215 { 216 this.getObjectManagementLogger().trace( message, throwable ); 217 } 218 else if ( level.equals( Level.INFO ) ) 219 { 220 this.getObjectManagementLogger().info( message, throwable ); 221 } 222 else if ( level.equals( Level.SEVERE ) ) 223 { 224 this.getObjectManagementLogger().error( message, throwable ); 225 } 226 else if ( level.equals( Level.WARNING ) ) 227 { 228 this.getObjectManagementLogger().warn( message, throwable ); 229 } 230 else 231 { 232 this.getObjectManagementLogger().trace( message, throwable ); 233 } 234 } 235 } 236 237 // SECTION-END 238 // SECTION-START[Log4JLogger] 239 /** 240 * Gets the Log4J logger backing the instance. 241 * 242 * @return The Log4J logger backing the instance. 243 * 244 * @see #getName() 245 * @see org.apache.log4j.Logger#getLogger(java.lang.String) 246 */ 247 public org.apache.log4j.Logger getLogger() 248 { 249 return org.apache.log4j.Logger.getLogger( this.getName() ); 250 } 251 252 // SECTION-END 253 // SECTION-START[Dependencies] 254 // <editor-fold defaultstate="collapsed" desc=" Generated Dependencies "> 255 /** 256 * Gets the {@code <ObjectManagementLogger>} dependency. 257 * <p> 258 * This method returns the {@code <JOMC Logging ⁑ Log4J Logging>} object of the {@code <org.jomc.logging.Logger>} specification at specification level 1.0. 259 * That specification does not apply to any scope. A new object is returned whenever requested and bound to this instance. 260 * </p> 261 * <p><strong>Properties:</strong> 262 * <table border="1" width="100%" cellpadding="3" cellspacing="0"> 263 * <tr class="TableSubHeadingColor"> 264 * <th align="left" scope="col" nowrap><b>Name</b></th> 265 * <th align="left" scope="col" nowrap><b>Type</b></th> 266 * <th align="left" scope="col" nowrap><b>Documentation</b></th> 267 * </tr> 268 * <tr class="TableRow"> 269 * <td align="left" valign="top" nowrap>{@code <name>}</td> 270 * <td align="left" valign="top" nowrap>{@code java.lang.String}</td> 271 * <td align="left" valign="top">Name of the logger object management events are logged with.</td> 272 * </tr> 273 * </table> 274 * </p> 275 * <dl> 276 * <dt><b>Final:</b></dt><dd>No</dd> 277 * </dl> 278 * @return Logger object management events are logged with. 279 * @throws org.jomc.ObjectManagementException if getting the dependency instance fails. 280 */ 281 @SuppressWarnings("unused") 282 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.4", comments = "See http://www.jomc.org/jomc/1.4/jomc-tools-1.4" ) 283 private org.jomc.logging.Logger getObjectManagementLogger() 284 { 285 final org.jomc.logging.Logger _d = (org.jomc.logging.Logger) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getDependency( this, "ObjectManagementLogger" ); 286 assert _d != null : "'ObjectManagementLogger' dependency not found."; 287 return _d; 288 } 289 // </editor-fold> 290 // SECTION-END 291 // SECTION-START[Properties] 292 // <editor-fold defaultstate="collapsed" desc=" Generated Properties "> 293 /** 294 * Gets the value of the {@code <name>} property. 295 * <p><dl> 296 * <dt><b>Final:</b></dt><dd>No</dd> 297 * </dl></p> 298 * @return Name of the component events are logged for. 299 * @throws org.jomc.ObjectManagementException if getting the property instance fails. 300 */ 301 @SuppressWarnings("unused") 302 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.4", comments = "See http://www.jomc.org/jomc/1.4/jomc-tools-1.4" ) 303 public java.lang.String getName() 304 { 305 final java.lang.String _p = (java.lang.String) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "name" ); 306 assert _p != null : "'name' property not found."; 307 return _p; 308 } 309 // </editor-fold> 310 // SECTION-END 311 // SECTION-START[Messages] 312 // SECTION-END 313}