1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.apache.maven.plugin.surefire.log;
20
21 import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
22 import org.slf4j.Logger;
23
24 /**
25 * Wrapper logger of miscellaneous implementations of {@link Logger}.
26 *
27 * This instance is synchronized. The logger operations are mutually exclusive to standard out, standard err and console
28 * err/warn/info/debug logger operations, see {@link org.apache.maven.plugin.surefire.report.DefaultReporterFactory},
29 * {@link org.apache.maven.plugin.surefire.report.TestSetRunListener}.
30 *
31 * @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
32 * @since 2.20
33 * @see ConsoleLogger
34 */
35 public final class PluginConsoleLogger implements ConsoleLogger {
36 private final Logger logger;
37
38 public PluginConsoleLogger(Logger logger) {
39 this.logger = logger;
40 }
41
42 @Override
43 public boolean isDebugEnabled() {
44 return logger.isDebugEnabled();
45 }
46
47 @Override
48 public synchronized void debug(String message) {
49 logger.debug(message);
50 }
51
52 public synchronized void debug(CharSequence content, Throwable error) {
53 logger.debug(content == null ? "" : content.toString(), error);
54 }
55
56 @Override
57 public boolean isInfoEnabled() {
58 return logger.isInfoEnabled();
59 }
60
61 @Override
62 public synchronized void info(String message) {
63 logger.info(message);
64 }
65
66 @Override
67 public boolean isWarnEnabled() {
68 return logger.isWarnEnabled();
69 }
70
71 @Override
72 public synchronized void warning(String message) {
73 logger.warn(message);
74 }
75
76 public synchronized void warning(CharSequence content, Throwable error) {
77 logger.warn(content == null ? "" : content.toString(), error);
78 }
79
80 @Override
81 public boolean isErrorEnabled() {
82 return logger.isErrorEnabled();
83 }
84
85 @Override
86 public synchronized void error(String message) {
87 logger.error(message);
88 }
89
90 @Override
91 public synchronized void error(String message, Throwable t) {
92 logger.error(message, t);
93 }
94
95 @Override
96 public synchronized void error(Throwable t) {
97 logger.error("", t);
98 }
99 }