2 * Copyright 2017-present Open Networking Foundation
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package io.atomix.utils.logging;
18 import org.slf4j.Logger;
19 import org.slf4j.Marker;
24 public class ContextualLogger extends DelegatingLogger {
25 private static final String SEPARATOR = " - ";
26 private final LoggerContext context;
28 public ContextualLogger(Logger delegate, LoggerContext context) {
30 this.context = context;
34 * Returns a contextualized version of the given string.
36 * @param msg the message to contextualize
37 * @return the contextualized message
39 private String contextualize(String msg) {
40 return context + SEPARATOR + msg;
44 public void trace(String msg) {
45 if (isTraceEnabled()) {
46 super.trace(contextualize(msg));
51 public void trace(String format, Object arg) {
52 if (isTraceEnabled()) {
53 super.trace(contextualize(format), arg);
58 public void trace(String format, Object arg1, Object arg2) {
59 if (isTraceEnabled()) {
60 super.trace(contextualize(format), arg1, arg2);
65 public void trace(String format, Object... arguments) {
66 if (isTraceEnabled()) {
67 super.trace(contextualize(format), arguments);
72 public void trace(String msg, Throwable t) {
73 if (isTraceEnabled()) {
74 super.trace(contextualize(msg), t);
79 public void trace(Marker marker, String msg) {
80 if (isTraceEnabled()) {
81 super.trace(marker, contextualize(msg));
86 public void trace(Marker marker, String format, Object arg) {
87 if (isTraceEnabled()) {
88 super.trace(marker, contextualize(format), arg);
93 public void trace(Marker marker, String format, Object arg1, Object arg2) {
94 if (isTraceEnabled()) {
95 super.trace(marker, contextualize(format), arg1, arg2);
100 public void trace(Marker marker, String format, Object... argArray) {
101 if (isTraceEnabled()) {
102 super.trace(marker, contextualize(format), argArray);
107 public void trace(Marker marker, String msg, Throwable t) {
108 if (isTraceEnabled()) {
109 super.trace(marker, contextualize(msg), t);
114 public void debug(String msg) {
115 if (isDebugEnabled()) {
116 super.debug(contextualize(msg));
121 public void debug(String format, Object arg) {
122 if (isDebugEnabled()) {
123 super.debug(contextualize(format), arg);
128 public void debug(String format, Object arg1, Object arg2) {
129 if (isDebugEnabled()) {
130 super.debug(contextualize(format), arg1, arg2);
135 public void debug(String format, Object... arguments) {
136 if (isDebugEnabled()) {
137 super.debug(contextualize(format), arguments);
142 public void debug(String msg, Throwable t) {
143 if (isDebugEnabled()) {
144 super.debug(contextualize(msg), t);
149 public void debug(Marker marker, String msg) {
150 if (isDebugEnabled()) {
151 super.debug(marker, contextualize(msg));
156 public void debug(Marker marker, String format, Object arg) {
157 if (isDebugEnabled()) {
158 super.debug(marker, contextualize(format), arg);
163 public void debug(Marker marker, String format, Object arg1, Object arg2) {
164 if (isDebugEnabled()) {
165 super.debug(marker, contextualize(format), arg1, arg2);
170 public void debug(Marker marker, String format, Object... arguments) {
171 if (isDebugEnabled()) {
172 super.debug(marker, contextualize(format), arguments);
177 public void debug(Marker marker, String msg, Throwable t) {
178 if (isDebugEnabled()) {
179 super.debug(marker, contextualize(msg), t);
184 public void info(String msg) {
185 if (isInfoEnabled()) {
186 super.info(contextualize(msg));
191 public void info(String format, Object arg) {
192 if (isInfoEnabled()) {
193 super.info(contextualize(format), arg);
198 public void info(String format, Object arg1, Object arg2) {
199 if (isInfoEnabled()) {
200 super.info(contextualize(format), arg1, arg2);
205 public void info(String format, Object... arguments) {
206 if (isInfoEnabled()) {
207 super.info(contextualize(format), arguments);
212 public void info(String msg, Throwable t) {
213 if (isInfoEnabled()) {
214 super.info(contextualize(msg), t);
219 public void info(Marker marker, String msg) {
220 if (isInfoEnabled()) {
221 super.info(marker, contextualize(msg));
226 public void info(Marker marker, String format, Object arg) {
227 if (isInfoEnabled()) {
228 super.info(marker, contextualize(format), arg);
233 public void info(Marker marker, String format, Object arg1, Object arg2) {
234 if (isInfoEnabled()) {
235 super.info(marker, contextualize(format), arg1, arg2);
240 public void info(Marker marker, String format, Object... arguments) {
241 if (isInfoEnabled()) {
242 super.info(marker, contextualize(format), arguments);
247 public void info(Marker marker, String msg, Throwable t) {
248 if (isInfoEnabled()) {
249 super.info(marker, contextualize(msg), t);
254 public void warn(String msg) {
255 if (isWarnEnabled()) {
256 super.warn(contextualize(msg));
261 public void warn(String format, Object arg) {
262 if (isWarnEnabled()) {
263 super.warn(contextualize(format), arg);
268 public void warn(String format, Object... arguments) {
269 if (isWarnEnabled()) {
270 super.warn(contextualize(format), arguments);
275 public void warn(String format, Object arg1, Object arg2) {
276 if (isWarnEnabled()) {
277 super.warn(contextualize(format), arg1, arg2);
282 public void warn(String msg, Throwable t) {
283 if (isWarnEnabled()) {
284 super.warn(contextualize(msg), t);
289 public void warn(Marker marker, String msg) {
290 if (isWarnEnabled()) {
291 super.warn(marker, contextualize(msg));
296 public void warn(Marker marker, String format, Object arg) {
297 if (isWarnEnabled()) {
298 super.warn(marker, contextualize(format), arg);
303 public void warn(Marker marker, String format, Object arg1, Object arg2) {
304 if (isWarnEnabled()) {
305 super.warn(marker, contextualize(format), arg1, arg2);
310 public void warn(Marker marker, String format, Object... arguments) {
311 if (isWarnEnabled()) {
312 super.warn(marker, contextualize(format), arguments);
317 public void warn(Marker marker, String msg, Throwable t) {
318 if (isWarnEnabled()) {
319 super.warn(marker, contextualize(msg), t);
324 public void error(String msg) {
325 if (isErrorEnabled()) {
326 super.error(contextualize(msg));
331 public void error(String format, Object arg) {
332 if (isErrorEnabled()) {
333 super.error(contextualize(format), arg);
338 public void error(String format, Object arg1, Object arg2) {
339 if (isErrorEnabled()) {
340 super.error(contextualize(format), arg1, arg2);
345 public void error(String format, Object... arguments) {
346 if (isErrorEnabled()) {
347 super.error(contextualize(format), arguments);
352 public void error(String msg, Throwable t) {
353 if (isErrorEnabled()) {
354 super.error(contextualize(msg), t);
359 public void error(Marker marker, String msg) {
360 if (isErrorEnabled()) {
361 super.error(marker, contextualize(msg));
366 public void error(Marker marker, String format, Object arg) {
367 if (isErrorEnabled()) {
368 super.error(marker, contextualize(format), arg);
373 public void error(Marker marker, String format, Object arg1, Object arg2) {
374 if (isErrorEnabled()) {
375 super.error(marker, contextualize(format), arg1, arg2);
380 public void error(Marker marker, String format, Object... arguments) {
381 if (isErrorEnabled()) {
382 super.error(marker, contextualize(format), arguments);
387 public void error(Marker marker, String msg, Throwable t) {
388 if (isErrorEnabled()) {
389 super.error(marker, contextualize(msg), t);