Import atomix/{storage,utils}
[controller.git] / third-party / atomix / utils / src / main / java / io / atomix / utils / logging / ContextualLogger.java
1 /*
2  * Copyright 2017-present Open Networking Foundation
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package io.atomix.utils.logging;
17
18 import org.slf4j.Logger;
19 import org.slf4j.Marker;
20
21 /**
22  * Contextual logger.
23  */
24 public class ContextualLogger extends DelegatingLogger {
25   private static final String SEPARATOR = " - ";
26   private final LoggerContext context;
27
28   public ContextualLogger(Logger delegate, LoggerContext context) {
29     super(delegate);
30     this.context = context;
31   }
32
33   /**
34    * Returns a contextualized version of the given string.
35    *
36    * @param msg the message to contextualize
37    * @return the contextualized message
38    */
39   private String contextualize(String msg) {
40     return context + SEPARATOR + msg;
41   }
42
43   @Override
44   public void trace(String msg) {
45     if (isTraceEnabled()) {
46       super.trace(contextualize(msg));
47     }
48   }
49
50   @Override
51   public void trace(String format, Object arg) {
52     if (isTraceEnabled()) {
53       super.trace(contextualize(format), arg);
54     }
55   }
56
57   @Override
58   public void trace(String format, Object arg1, Object arg2) {
59     if (isTraceEnabled()) {
60       super.trace(contextualize(format), arg1, arg2);
61     }
62   }
63
64   @Override
65   public void trace(String format, Object... arguments) {
66     if (isTraceEnabled()) {
67       super.trace(contextualize(format), arguments);
68     }
69   }
70
71   @Override
72   public void trace(String msg, Throwable t) {
73     if (isTraceEnabled()) {
74       super.trace(contextualize(msg), t);
75     }
76   }
77
78   @Override
79   public void trace(Marker marker, String msg) {
80     if (isTraceEnabled()) {
81       super.trace(marker, contextualize(msg));
82     }
83   }
84
85   @Override
86   public void trace(Marker marker, String format, Object arg) {
87     if (isTraceEnabled()) {
88       super.trace(marker, contextualize(format), arg);
89     }
90   }
91
92   @Override
93   public void trace(Marker marker, String format, Object arg1, Object arg2) {
94     if (isTraceEnabled()) {
95       super.trace(marker, contextualize(format), arg1, arg2);
96     }
97   }
98
99   @Override
100   public void trace(Marker marker, String format, Object... argArray) {
101     if (isTraceEnabled()) {
102       super.trace(marker, contextualize(format), argArray);
103     }
104   }
105
106   @Override
107   public void trace(Marker marker, String msg, Throwable t) {
108     if (isTraceEnabled()) {
109       super.trace(marker, contextualize(msg), t);
110     }
111   }
112
113   @Override
114   public void debug(String msg) {
115     if (isDebugEnabled()) {
116       super.debug(contextualize(msg));
117     }
118   }
119
120   @Override
121   public void debug(String format, Object arg) {
122     if (isDebugEnabled()) {
123       super.debug(contextualize(format), arg);
124     }
125   }
126
127   @Override
128   public void debug(String format, Object arg1, Object arg2) {
129     if (isDebugEnabled()) {
130       super.debug(contextualize(format), arg1, arg2);
131     }
132   }
133
134   @Override
135   public void debug(String format, Object... arguments) {
136     if (isDebugEnabled()) {
137       super.debug(contextualize(format), arguments);
138     }
139   }
140
141   @Override
142   public void debug(String msg, Throwable t) {
143     if (isDebugEnabled()) {
144       super.debug(contextualize(msg), t);
145     }
146   }
147
148   @Override
149   public void debug(Marker marker, String msg) {
150     if (isDebugEnabled()) {
151       super.debug(marker, contextualize(msg));
152     }
153   }
154
155   @Override
156   public void debug(Marker marker, String format, Object arg) {
157     if (isDebugEnabled()) {
158       super.debug(marker, contextualize(format), arg);
159     }
160   }
161
162   @Override
163   public void debug(Marker marker, String format, Object arg1, Object arg2) {
164     if (isDebugEnabled()) {
165       super.debug(marker, contextualize(format), arg1, arg2);
166     }
167   }
168
169   @Override
170   public void debug(Marker marker, String format, Object... arguments) {
171     if (isDebugEnabled()) {
172       super.debug(marker, contextualize(format), arguments);
173     }
174   }
175
176   @Override
177   public void debug(Marker marker, String msg, Throwable t) {
178     if (isDebugEnabled()) {
179       super.debug(marker, contextualize(msg), t);
180     }
181   }
182
183   @Override
184   public void info(String msg) {
185     if (isInfoEnabled()) {
186       super.info(contextualize(msg));
187     }
188   }
189
190   @Override
191   public void info(String format, Object arg) {
192     if (isInfoEnabled()) {
193       super.info(contextualize(format), arg);
194     }
195   }
196
197   @Override
198   public void info(String format, Object arg1, Object arg2) {
199     if (isInfoEnabled()) {
200       super.info(contextualize(format), arg1, arg2);
201     }
202   }
203
204   @Override
205   public void info(String format, Object... arguments) {
206     if (isInfoEnabled()) {
207       super.info(contextualize(format), arguments);
208     }
209   }
210
211   @Override
212   public void info(String msg, Throwable t) {
213     if (isInfoEnabled()) {
214       super.info(contextualize(msg), t);
215     }
216   }
217
218   @Override
219   public void info(Marker marker, String msg) {
220     if (isInfoEnabled()) {
221       super.info(marker, contextualize(msg));
222     }
223   }
224
225   @Override
226   public void info(Marker marker, String format, Object arg) {
227     if (isInfoEnabled()) {
228       super.info(marker, contextualize(format), arg);
229     }
230   }
231
232   @Override
233   public void info(Marker marker, String format, Object arg1, Object arg2) {
234     if (isInfoEnabled()) {
235       super.info(marker, contextualize(format), arg1, arg2);
236     }
237   }
238
239   @Override
240   public void info(Marker marker, String format, Object... arguments) {
241     if (isInfoEnabled()) {
242       super.info(marker, contextualize(format), arguments);
243     }
244   }
245
246   @Override
247   public void info(Marker marker, String msg, Throwable t) {
248     if (isInfoEnabled()) {
249       super.info(marker, contextualize(msg), t);
250     }
251   }
252
253   @Override
254   public void warn(String msg) {
255     if (isWarnEnabled()) {
256       super.warn(contextualize(msg));
257     }
258   }
259
260   @Override
261   public void warn(String format, Object arg) {
262     if (isWarnEnabled()) {
263       super.warn(contextualize(format), arg);
264     }
265   }
266
267   @Override
268   public void warn(String format, Object... arguments) {
269     if (isWarnEnabled()) {
270       super.warn(contextualize(format), arguments);
271     }
272   }
273
274   @Override
275   public void warn(String format, Object arg1, Object arg2) {
276     if (isWarnEnabled()) {
277       super.warn(contextualize(format), arg1, arg2);
278     }
279   }
280
281   @Override
282   public void warn(String msg, Throwable t) {
283     if (isWarnEnabled()) {
284       super.warn(contextualize(msg), t);
285     }
286   }
287
288   @Override
289   public void warn(Marker marker, String msg) {
290     if (isWarnEnabled()) {
291       super.warn(marker, contextualize(msg));
292     }
293   }
294
295   @Override
296   public void warn(Marker marker, String format, Object arg) {
297     if (isWarnEnabled()) {
298       super.warn(marker, contextualize(format), arg);
299     }
300   }
301
302   @Override
303   public void warn(Marker marker, String format, Object arg1, Object arg2) {
304     if (isWarnEnabled()) {
305       super.warn(marker, contextualize(format), arg1, arg2);
306     }
307   }
308
309   @Override
310   public void warn(Marker marker, String format, Object... arguments) {
311     if (isWarnEnabled()) {
312       super.warn(marker, contextualize(format), arguments);
313     }
314   }
315
316   @Override
317   public void warn(Marker marker, String msg, Throwable t) {
318     if (isWarnEnabled()) {
319       super.warn(marker, contextualize(msg), t);
320     }
321   }
322
323   @Override
324   public void error(String msg) {
325     if (isErrorEnabled()) {
326       super.error(contextualize(msg));
327     }
328   }
329
330   @Override
331   public void error(String format, Object arg) {
332     if (isErrorEnabled()) {
333       super.error(contextualize(format), arg);
334     }
335   }
336
337   @Override
338   public void error(String format, Object arg1, Object arg2) {
339     if (isErrorEnabled()) {
340       super.error(contextualize(format), arg1, arg2);
341     }
342   }
343
344   @Override
345   public void error(String format, Object... arguments) {
346     if (isErrorEnabled()) {
347       super.error(contextualize(format), arguments);
348     }
349   }
350
351   @Override
352   public void error(String msg, Throwable t) {
353     if (isErrorEnabled()) {
354       super.error(contextualize(msg), t);
355     }
356   }
357
358   @Override
359   public void error(Marker marker, String msg) {
360     if (isErrorEnabled()) {
361       super.error(marker, contextualize(msg));
362     }
363   }
364
365   @Override
366   public void error(Marker marker, String format, Object arg) {
367     if (isErrorEnabled()) {
368       super.error(marker, contextualize(format), arg);
369     }
370   }
371
372   @Override
373   public void error(Marker marker, String format, Object arg1, Object arg2) {
374     if (isErrorEnabled()) {
375       super.error(marker, contextualize(format), arg1, arg2);
376     }
377   }
378
379   @Override
380   public void error(Marker marker, String format, Object... arguments) {
381     if (isErrorEnabled()) {
382       super.error(marker, contextualize(format), arguments);
383     }
384   }
385
386   @Override
387   public void error(Marker marker, String msg, Throwable t) {
388     if (isErrorEnabled()) {
389       super.error(marker, contextualize(msg), t);
390     }
391   }
392 }