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 implementations of {@link Logger}.
27   *
28   * This instance is synchronized. The logger operations are mutually exclusive to standard out, standard err and console
29   * err/warn/info/debug logger operations, see {@link org.apache.maven.plugin.surefire.report.DefaultReporterFactory},
30   * {@link org.apache.maven.plugin.surefire.report.TestSetRunListener}.
31   *
32   * @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
33   * @since 2.20
34   * @see ConsoleLogger
35   */
36  public final class PluginConsoleLogger
37      implements ConsoleLogger
38  {
39      private final Logger plexusLogger;
40  
41      public PluginConsoleLogger( Logger plexusLogger )
42      {
43          this.plexusLogger = plexusLogger;
44      }
45  
46      @Override
47      public boolean isDebugEnabled()
48      {
49          return plexusLogger.isDebugEnabled();
50      }
51  
52      @Override
53      public synchronized void debug( String message )
54      {
55          plexusLogger.debug( message );
56      }
57  
58      public synchronized void debug( CharSequence content, Throwable error )
59      {
60          plexusLogger.debug( content == null ? "" : content.toString(), error );
61      }
62  
63      @Override
64      public boolean isInfoEnabled()
65      {
66          return plexusLogger.isInfoEnabled();
67      }
68  
69      @Override
70      public synchronized void info( String message )
71      {
72          plexusLogger.info( message );
73      }
74  
75      @Override
76      public boolean isWarnEnabled()
77      {
78          return plexusLogger.isWarnEnabled();
79      }
80  
81      @Override
82      public synchronized void warning( String message )
83      {
84          plexusLogger.warn( message );
85      }
86  
87      public synchronized void warning( CharSequence content, Throwable error )
88      {
89          plexusLogger.warn( content == null ? "" : content.toString(), error );
90      }
91  
92      @Override
93      public boolean isErrorEnabled()
94      {
95          return plexusLogger.isErrorEnabled() || plexusLogger.isFatalErrorEnabled();
96      }
97  
98      @Override
99      public synchronized void error( String message )
100     {
101         plexusLogger.error( message );
102     }
103 
104     @Override
105     public synchronized void error( String message, Throwable t )
106     {
107         plexusLogger.error( message, t );
108     }
109 
110     @Override
111     public synchronized void error( Throwable t )
112     {
113         plexusLogger.error( "", t );
114     }
115 }