View Javadoc

1   /*
2    *  jDTAUS Core RI Log4J Logging
3    *  Copyright (C) 2005 Christian Schulte
4    *  <cs@schulte.it>
5    *
6    *  This library is free software; you can redistribute it and/or
7    *  modify it under the terms of the GNU Lesser General Public
8    *  License as published by the Free Software Foundation; either
9    *  version 2.1 of the License, or any later version.
10   *
11   *  This library is distributed in the hope that it will be useful,
12   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   *  Lesser General Public License for more details.
15   *
16   *  You should have received a copy of the GNU Lesser General Public
17   *  License along with this library; if not, write to the Free Software
18   *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19   *
20   */
21  package org.jdtaus.core.logging.ri.log4j;
22  
23  import org.jdtaus.core.container.ContainerFactory;
24  import org.jdtaus.core.logging.spi.Logger;
25  
26  /**
27   * jDTAUS Core SPI Log4J {@code Logger} implementation.
28   * <p>The name of the Log4J logger is specified by property {@code name}.
29   * Property {@code name} defaults to {@code org.jdtaus.runtime}.</p>
30   *
31   * @author <a href="mailto:cs@schulte.it">Christian Schulte</a>
32   * @version $JDTAUS: Log4JLogger.java 8641 2012-09-27 06:45:17Z schulte $
33   *
34   * @see org.jdtaus.core.container.Container
35   */
36  public class Log4JLogger implements Logger
37  {
38      //--Constructors------------------------------------------------------------
39  
40  // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:jdtausConstructors
41      // This section is managed by jdtaus-container-mojo.
42  
43      /** Standard implementation constructor <code>org.jdtaus.core.logging.ri.log4j.Log4JLogger</code>. */
44      public Log4JLogger()
45      {
46          super();
47      }
48  
49  // </editor-fold>//GEN-END:jdtausConstructors
50  
51      //------------------------------------------------------------Constructors--
52      //--Properties--------------------------------------------------------------
53  
54  // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:jdtausProperties
55      // This section is managed by jdtaus-container-mojo.
56  
57      /**
58       * Gets the value of property <code>name</code>.
59       *
60       * @return Name uniquely identifying the logger.
61       */
62      public java.lang.String getName()
63      {
64          return (java.lang.String) ContainerFactory.getContainer().
65              getProperty( this, "name" );
66  
67      }
68  
69  // </editor-fold>//GEN-END:jdtausProperties
70  
71      //--------------------------------------------------------------Properties--
72      //--Logger------------------------------------------------------------------
73  
74      public boolean isDebugEnabled()
75      {
76          return this.getLogger().isEnabledFor( org.apache.log4j.Level.DEBUG );
77      }
78  
79      public void debug( String string )
80      {
81          this.getLogger().debug( string );
82      }
83  
84      public void debug( Throwable throwable )
85      {
86          this.getLogger().debug( throwable.getMessage(), throwable );
87      }
88  
89      public boolean isErrorEnabled()
90      {
91          return this.getLogger().isEnabledFor( org.apache.log4j.Level.ERROR );
92      }
93  
94      public void error( String string )
95      {
96          this.getLogger().error( string );
97      }
98  
99      public void error( Throwable throwable )
100     {
101         this.getLogger().error( throwable.getMessage(), throwable );
102     }
103 
104     public boolean isFatalEnabled()
105     {
106         return this.getLogger().isEnabledFor( org.apache.log4j.Level.FATAL );
107     }
108 
109     public void fatal( String string )
110     {
111         this.getLogger().fatal( string );
112     }
113 
114     public void fatal( Throwable throwable )
115     {
116         this.getLogger().fatal( throwable.getMessage(), throwable );
117     }
118 
119     public boolean isInfoEnabled()
120     {
121         return this.getLogger().isEnabledFor( org.apache.log4j.Level.INFO );
122     }
123 
124     public void info( String string )
125     {
126         this.getLogger().info( string );
127     }
128 
129     public void info( Throwable throwable )
130     {
131         this.getLogger().info( throwable.getMessage(), throwable );
132     }
133 
134     public boolean isTraceEnabled()
135     {
136         return this.getLogger().isEnabledFor( org.apache.log4j.Level.TRACE );
137     }
138 
139     public void trace( String string )
140     {
141         this.getLogger().trace( string );
142     }
143 
144     public void trace( Throwable throwable )
145     {
146         this.getLogger().trace( throwable.getMessage(), throwable );
147     }
148 
149     public boolean isWarnEnabled()
150     {
151         return this.getLogger().isEnabledFor( org.apache.log4j.Level.WARN );
152     }
153 
154     public void warn( String string )
155     {
156         this.getLogger().warn( string );
157     }
158 
159     public void warn( Throwable throwable )
160     {
161         this.getLogger().warn( throwable.getMessage(), throwable );
162     }
163 
164     //------------------------------------------------------------------Logger--
165     //--Log4JLogger-------------------------------------------------------------
166 
167     /**
168      * Requests a Log4J logger for the name given by property {@code name}.
169      *
170      * @return the Log4J logger for the name given by property {@code name}.
171      */
172     public org.apache.log4j.Logger getLogger()
173     {
174         return org.apache.log4j.Logger.getLogger( this.getName() );
175     }
176 
177     //-------------------------------------------------------------Log4JLogger--
178 }