This project has retired. For details please refer to its Attic page.
Slf4JPlexusLogger xref
View Javadoc
1   package org.apache.archiva.common.utils;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.slf4j.Logger;
23  import org.slf4j.LoggerFactory;
24  
25  /**
26   * Slf4JPlexusLogger - temporary logger to provide an Slf4j Logger to those components
27   * outside of the archiva codebase that require a plexus logger.
28   *
29   *
30   */
31  public class Slf4JPlexusLogger
32      implements org.codehaus.plexus.logging.Logger
33  {
34      private final Logger log;
35  
36      public Slf4JPlexusLogger( Class<?> clazz )
37      {
38          log = LoggerFactory.getLogger( clazz );
39      }
40  
41      public Slf4JPlexusLogger( String name )
42      {
43          log = LoggerFactory.getLogger( name );
44      }
45  
46      @Override
47      public void debug( String message )
48      {
49          log.debug( message );
50      }
51  
52      @Override
53      public void debug( String message, Throwable throwable )
54      {
55          log.debug( message, throwable );
56      }
57  
58      @Override
59      public void error( String message )
60      {
61          log.error( message );
62      }
63  
64      @Override
65      public void error( String message, Throwable throwable )
66      {
67          log.error( message, throwable );
68      }
69  
70      @Override
71      public void fatalError( String message )
72      {
73          log.error( message );
74      }
75  
76      @Override
77      public void fatalError( String message, Throwable throwable )
78      {
79          log.error( message, throwable );
80      }
81  
82      @Override
83      public org.codehaus.plexus.logging.Logger getChildLogger( String name )
84      {
85          return new Slf4JPlexusLogger( log.getName() + "." + name );
86      }
87  
88      @Override
89      public String getName()
90      {
91          return log.getName();
92      }
93  
94      @Override
95      public int getThreshold()
96      {
97          if ( log.isTraceEnabled() )
98          {
99              return org.codehaus.plexus.logging.Logger.LEVEL_DEBUG;
100         }
101         else if ( log.isDebugEnabled() )
102         {
103             return org.codehaus.plexus.logging.Logger.LEVEL_DEBUG;
104         }
105         else if ( log.isInfoEnabled() )
106         {
107             return org.codehaus.plexus.logging.Logger.LEVEL_INFO;
108         }
109         else if ( log.isWarnEnabled() )
110         {
111             return org.codehaus.plexus.logging.Logger.LEVEL_WARN;
112         }
113         else if ( log.isErrorEnabled() )
114         {
115             return org.codehaus.plexus.logging.Logger.LEVEL_ERROR;
116         }
117 
118         return org.codehaus.plexus.logging.Logger.LEVEL_DISABLED;
119     }
120 
121     @Override
122     public void info( String message )
123     {
124         log.info( message );
125     }
126 
127     @Override
128     public void info( String message, Throwable throwable )
129     {
130         log.info( message, throwable );
131     }
132 
133     @Override
134     public boolean isDebugEnabled()
135     {
136         return log.isDebugEnabled();
137     }
138 
139     @Override
140     public boolean isErrorEnabled()
141     {
142         return log.isErrorEnabled();
143     }
144 
145     @Override
146     public boolean isFatalErrorEnabled()
147     {
148         return log.isErrorEnabled();
149     }
150 
151     @Override
152     public boolean isInfoEnabled()
153     {
154         return log.isInfoEnabled();
155     }
156 
157     @Override
158     public boolean isWarnEnabled()
159     {
160         return log.isWarnEnabled();
161     }
162 
163     @Override
164     public void setThreshold( int threshold )
165     {
166         /* do nothing */
167     }
168 
169     @Override
170     public void warn( String message )
171     {
172         log.warn( message );
173     }
174 
175     @Override
176     public void warn( String message, Throwable throwable )
177     {
178         log.warn( message, throwable );
179     }
180 }