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