| 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: Log4JLogger.java 4723 2013-01-03 08:50:05Z schulte $ |
| 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.0</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.2 |
| 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.4", comments = "See http://www.jomc.org/jomc/1.4/jomc-tools-1.4" ) |
| 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.4", comments = "See http://www.jomc.org/jomc/1.4/jomc-tools-1.4" ) |
| 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 isDebugEnabled() |
| 85 | { |
| 86 | return this.getLogger().isEnabledFor( org.apache.log4j.Level.DEBUG ); |
| 87 | } |
| 88 | |
| 89 | public void debug( final String string ) |
| 90 | { |
| 91 | this.getLogger().debug( string ); |
| 92 | } |
| 93 | |
| 94 | public void debug( final Throwable throwable ) |
| 95 | { |
| 96 | this.getLogger().debug( throwable.getMessage(), throwable ); |
| 97 | } |
| 98 | |
| 99 | 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 | } |