View Javadoc
1   package org.apache.maven.plugin.surefire.log;
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.apache.maven.plugin.surefire.log.api.ConsoleLogger;
23  import org.codehaus.plexus.logging.Logger;
24  
25  /**
26   * Wrapper logger of miscellaneous (Maven 2.2.1 or 3.1) implementations of {@link Logger}.
27   * Calling {@link Logger#isInfoEnabled()} before {@link Logger#info(String)} due to Maven 2.2.1.
28   *
29   * @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
30   * @since 2.20
31   * @see ConsoleLogger
32   */
33  public final class PluginConsoleLogger
34      implements ConsoleLogger
35  {
36      private final Logger plexusLogger;
37  
38      public PluginConsoleLogger( Logger plexusLogger )
39      {
40          this.plexusLogger = plexusLogger;
41      }
42  
43      @Override
44      public boolean isDebugEnabled()
45      {
46          return plexusLogger.isDebugEnabled();
47      }
48  
49      @Override
50      public void debug( String message )
51      {
52          if ( isDebugEnabled() )
53          {
54              plexusLogger.debug( message );
55          }
56      }
57  
58      public void debug( CharSequence content, Throwable error )
59      {
60          if ( isDebugEnabled() )
61          {
62              plexusLogger.debug( content == null ? "" : content.toString(), error );
63          }
64      }
65  
66      @Override
67      public boolean isInfoEnabled()
68      {
69          return plexusLogger.isInfoEnabled();
70      }
71  
72      @Override
73      public void info( String message )
74      {
75          if ( isInfoEnabled() )
76          {
77              plexusLogger.info( message );
78          }
79      }
80  
81      @Override
82      public boolean isWarnEnabled()
83      {
84          return plexusLogger.isWarnEnabled();
85      }
86  
87      @Override
88      public void warning( String message )
89      {
90          if ( isWarnEnabled() )
91          {
92              plexusLogger.warn( message );
93          }
94      }
95  
96      public void warning( CharSequence content, Throwable error )
97      {
98          if ( isWarnEnabled() )
99          {
100             plexusLogger.warn( content == null ? "" : content.toString(), error );
101         }
102     }
103 
104     @Override
105     public boolean isErrorEnabled()
106     {
107         return plexusLogger.isErrorEnabled() || plexusLogger.isFatalErrorEnabled();
108     }
109 
110     @Override
111     public void error( String message )
112     {
113         if ( isErrorEnabled() )
114         {
115             plexusLogger.error( message );
116         }
117     }
118 
119     @Override
120     public void error( String message, Throwable t )
121     {
122         if ( isErrorEnabled() )
123         {
124             plexusLogger.error( message, t );
125         }
126     }
127 
128     @Override
129     public void error( Throwable t )
130     {
131         if ( isErrorEnabled() )
132         {
133             plexusLogger.error( "", t );
134         }
135     }
136 }