View Javadoc
1   /*
2    * Copyright (c) 2002-2017, Mairie de Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
33   */
34  package fr.paris.lutece.plugins.jsr168.pluto.services.log;
35  
36  import fr.paris.lutece.plugins.jsr168.pluto.LutecePlutoConstant;
37  import fr.paris.lutece.portal.service.util.AppLogService;
38  
39  import org.apache.commons.logging.LogFactory;
40  
41  import org.apache.pluto.portalImpl.services.log.LogService;
42  import org.apache.pluto.portalImpl.services.log.LoggerImpl;
43  import org.apache.pluto.portalImpl.util.Properties;
44  import org.apache.pluto.services.log.Logger;
45  
46  
47  /**
48   * Log service linked to Lutece/Pluto
49   * TODO : see if this class can be removed
50   */
51  public class LogServiceImpl extends LogService
52  {
53      private boolean _bIsDebugEnabled;
54      private boolean _bIsInfoEnabled;
55      private boolean _bIsWarnEnabled;
56      private boolean _bIsErrorEnabled;
57  
58      /**
59       * Initialize service with LogService
60       *
61       * @param aProperties Initialize properties
62       */
63      public void init( Properties aProperties )
64      {
65          _bIsDebugEnabled = aProperties.getBoolean( LutecePlutoConstant.CONFIG_SERVICES_LOG_DEBUG_ENABLED,
66                  LutecePlutoConstant.CONFIG_SERVICES_LOG_DEBUG_ENABLED_DEFAULT ).booleanValue(  );
67          _bIsInfoEnabled = aProperties.getBoolean( LutecePlutoConstant.CONFIG_SERVICES_LOG_INFO_ENABLED,
68                  LutecePlutoConstant.CONFIG_SERVICES_LOG_INFO_ENABLED_DEFAULT ).booleanValue(  );
69          _bIsWarnEnabled = aProperties.getBoolean( LutecePlutoConstant.CONFIG_SERVICES_LOG_WARN_ENABLED,
70                  LutecePlutoConstant.CONFIG_SERVICES_LOG_WARN_ENABLED_DEFAULT ).booleanValue(  );
71          _bIsErrorEnabled = aProperties.getBoolean( LutecePlutoConstant.CONFIG_SERVICES_LOG_ERROR_ENABLED,
72                  LutecePlutoConstant.CONFIG_SERVICES_LOG_ERROR_ENABLED_DEFAULT ).booleanValue(  );
73      }
74  
75      /**
76       * @see org.apache.pluto.services.log.LogService#isDebugEnabled(java.lang.String)
77       */
78      public boolean isDebugEnabled( String aComponent )
79      {
80          return _bIsDebugEnabled;
81      }
82  
83      /**
84       * @see org.apache.pluto.services.log.LogService#isInfoEnabled(java.lang.String)
85       */
86      public boolean isInfoEnabled( String aComponent )
87      {
88          return _bIsInfoEnabled;
89      }
90  
91      /**
92       * @see org.apache.pluto.services.log.LogService#isWarnEnabled(java.lang.String)
93       */
94      public boolean isWarnEnabled( String aComponent )
95      {
96          return _bIsWarnEnabled;
97      }
98  
99      /**
100      * @see org.apache.pluto.services.log.LogService#isErrorEnabled(java.lang.String)
101      */
102     public boolean isErrorEnabled( String aComponent )
103     {
104         return _bIsErrorEnabled;
105     }
106 
107     /**
108      * @see org.apache.pluto.services.log.LogService#debug(java.lang.String, java.lang.String)
109      */
110     public void debug( String aComponent, String aMessage )
111     {
112         AppLogService.debug( aComponent + ": " + aMessage );
113     }
114 
115     /**
116      * @see org.apache.pluto.services.log.LogService#debug(java.lang.String, java.lang.String, java.lang.Throwable)
117      */
118     public void debug( String aComponent, String aMessage, Throwable aThrowable )
119     {
120         AppLogService.debug( aComponent + ": " + aMessage, aThrowable );
121     }
122 
123     /**
124      * @see org.apache.pluto.services.log.LogService#info(java.lang.String, java.lang.String)
125      */
126     public void info( String aComponent, String aMessage )
127     {
128         AppLogService.info( aComponent + ": " + aMessage );
129     }
130 
131     /**
132      * @see org.apache.pluto.services.log.LogService#warn(java.lang.String, java.lang.String)
133      */
134     public void warn( String aComponent, String aMessage )
135     {
136         AppLogService.info( aComponent + ": " + aMessage );
137     }
138 
139     /**
140      * @see org.apache.pluto.services.log.LogService#error(java.lang.String, java.lang.String, java.lang.Throwable)
141      */
142     public void error( String aComponent, String aMessage, Throwable aThrowable )
143     {
144         AppLogService.error( aComponent + ": " + aMessage, aThrowable );
145     }
146 
147     /**
148      * @see org.apache.pluto.services.log.LogService#error(java.lang.String, java.lang.Throwable)
149      */
150     public void error( String aComponent, Throwable aThrowable )
151     {
152         AppLogService.error( aComponent, aThrowable );
153     }
154 
155     // FIXME
156     public Logger getLogger( String component )
157     {
158         return new LoggerImpl( LogFactory.getLog( component ) );
159     }
160 
161     //  FIXME
162     public Logger getLogger( Class klass )
163     {
164         return new LoggerImpl( LogFactory.getLog( klass ) );
165     }
166 }