2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.common.log.wrappers;
23 import com.google.common.annotations.VisibleForTesting;
24 import org.openecomp.sdc.common.config.EcompErrorConfiguration;
25 import org.openecomp.sdc.common.log.elements.LoggerDebug;
26 import org.openecomp.sdc.common.log.elements.LoggerError;
27 import org.openecomp.sdc.common.log.elements.LoggerFactory;
28 import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode;
29 import org.openecomp.sdc.common.log.enums.LogLevel;
30 import org.slf4j.Marker;
34 * This class wraps {@link org.slf4j.Logger} object and provides mandatory information required by Ecomp logging rules.
35 * Note: All deprecated methods are supported to be compatible to the legacy code
36 * and have not be used by the new code
38 public class Logger implements org.slf4j.Logger {
39 private final LoggerDebug debug;
40 private final LoggerError error;
41 private final org.slf4j.Logger logger;
44 private Logger(org.slf4j.Logger logger) {
46 this.debug = LoggerFactory.getMdcLogger(LoggerDebug.class, logger);
47 this.error = LoggerFactory.getMdcLogger(LoggerError.class, logger);
50 private Logger(String className) {
51 this(org.slf4j.LoggerFactory.getLogger(className));
54 public static Logger getLogger(String className) {
55 return new Logger(className);
58 public static Logger getLogger(Class<?> clazz) {
59 return new Logger(clazz.getName());
63 public boolean isDebugEnabled() {
64 return logger.isDebugEnabled();
68 public String getName() {
69 return logger.getName();
72 public boolean isTraceEnabled() {
73 return logger.isTraceEnabled();
76 public boolean isErrorEnabled() { return logger.isErrorEnabled(); }
78 public boolean isWarnEnabled() { return logger.isWarnEnabled(); }
81 @Deprecated /** Please use method {@link #warn(EcompLoggerErrorCode, String, String)} **/
82 public void warn(String msg) {
83 if (isWarnEnabled()) {
84 error.log(LogLevel.WARN, msg);
89 @Deprecated /** Please use method {@link #warn(EcompLoggerErrorCode, String, String)} **/
90 public void warn(String msg, Object o) {
92 if (isWarnEnabled()) {
93 error.log(LogLevel.WARN, msg, o);
97 public boolean isInfoEnabled() { return logger.isInfoEnabled(); }
100 public void info(String msg) {
101 if (isInfoEnabled()) {
102 error.logInfo(LogLevel.INFO, msg);
107 public void info(String msg, Object o) {
108 if (isInfoEnabled()) {
109 error.logInfo(LogLevel.INFO, msg, o);
114 public void info(String msg, Object o, Object o1) {
115 if (isInfoEnabled()) {
116 error.logInfo(LogLevel.INFO, msg, o, o1);
120 public void debug(String msg, Object... params) {
121 if (isDebugEnabled()) {
122 debug.log(LogLevel.DEBUG, msg, params);
127 public void debug(String msg, Throwable throwable) {
128 if (isDebugEnabled()) {
129 debug.log(LogLevel.DEBUG, msg, throwable);
134 public boolean isDebugEnabled(Marker marker) {
139 public void debug(Marker marker, String msg) {
140 if (isDebugEnabled()) {
141 debug.log(LogLevel.DEBUG, msg);
146 public void debug(Marker marker, String msg, Object o) {
147 if (isDebugEnabled()) {
148 debug.log(LogLevel.DEBUG, msg, o);
153 public void debug(Marker marker, String msg, Object o, Object o1) {
154 if (isDebugEnabled()) {
155 debug.log(LogLevel.DEBUG, msg, o, o1);
160 public void debug(Marker marker, String msg, Object... objects) {
161 if (isDebugEnabled()) {
162 debug.log(LogLevel.DEBUG, msg, objects);
167 public void debug(Marker marker, String msg, Throwable throwable) {
168 if (isDebugEnabled()) {
169 debug.log(LogLevel.DEBUG, msg, throwable);
173 public void debug(String message) {
174 if (isDebugEnabled()) {
175 debug.log(LogLevel.DEBUG, message);
180 public void debug(String msg, Object o) {
181 if (isDebugEnabled()) {
182 debug.log(LogLevel.DEBUG, msg, o);
187 public void debug(String msg, Object o, Object o1) {
188 if (isDebugEnabled()) {
189 debug.log(LogLevel.DEBUG, msg, o, o1);
193 public void trace(String message, Object... params) {
194 if (isTraceEnabled()) {
195 debug.log(LogLevel.TRACE, message, params);
200 public void trace(String msg, Throwable throwable) {
201 if (isTraceEnabled()) {
202 debug.log(LogLevel.TRACE, msg, throwable);
207 public boolean isTraceEnabled(Marker marker) {
212 public void trace(Marker marker, String msg) {
213 if (isTraceEnabled()) {
214 debug.log(LogLevel.TRACE, msg);
219 public void trace(Marker marker, String msg, Object o) {
220 if (isTraceEnabled()) {
221 debug.log(LogLevel.TRACE, msg, o);
226 public void trace(Marker marker, String msg, Object o, Object o1) {
227 if (isTraceEnabled()) {
228 debug.log(LogLevel.TRACE, msg, o, o1);
233 public void trace(Marker marker, String msg, Object... objects) {
234 if (isTraceEnabled()) {
235 debug.log(LogLevel.TRACE, msg, objects);
240 public void trace(Marker marker, String msg, Throwable throwable) {
241 if (isTraceEnabled()) {
242 debug.log(LogLevel.TRACE, msg, throwable);
246 public void trace(String msg) {
247 if (isTraceEnabled()) {
248 debug.log(LogLevel.TRACE, msg);
253 public void trace(String msg, Object o) {
254 if (isTraceEnabled()) {
255 debug.log(LogLevel.TRACE, msg, o);
260 public void trace(String msg, Object o, Object o1) {
261 if (isTraceEnabled()) {
262 debug.log(LogLevel.TRACE, msg, o, o1);
266 public void info(String msg, Object... params) {
267 if (isInfoEnabled()) {
268 error.logInfo(LogLevel.INFO, msg, params);
273 public void info(String msg, Throwable throwable) {
274 if (isInfoEnabled()) {
275 error.logInfo(LogLevel.INFO, msg, throwable);
280 public boolean isInfoEnabled(Marker marker) {
285 public void info(Marker marker, String msg) {
286 if (isInfoEnabled()) {
287 error.logInfo(LogLevel.INFO, msg);
292 public void info(Marker marker, String msg, Object o) {
293 if (isInfoEnabled()) {
294 error.logInfo(LogLevel.INFO, msg, o);
299 public void info(Marker marker, String msg, Object o, Object o1) {
300 if (isInfoEnabled()) {
301 error.logInfo(LogLevel.INFO, msg, o, o1);
306 public void info(Marker marker, String msg, Object... objects) {
307 if (isInfoEnabled()) {
308 error.logInfo(LogLevel.INFO, msg, objects);
313 public void info(Marker marker, String msg, Throwable throwable) {
314 if (isInfoEnabled()) {
315 error.logInfo(LogLevel.INFO, msg, throwable);
319 @Deprecated /** Please use method {@link #warn(EcompLoggerErrorCode, String, String)} **/
320 public void warn(String msg, Object... params){
321 if (isWarnEnabled()) {
322 error.log(LogLevel.WARN, msg, params);
327 @Deprecated /** Please use method {@link #warn(EcompLoggerErrorCode, String, String)} **/
328 public void warn(String msg, Object o, Object o1) {
329 if (isWarnEnabled()) {
330 error.log(LogLevel.WARN, msg, o, o1);
335 @Deprecated /** Please use method {@link #warn(EcompLoggerErrorCode, String, String)} **/
336 public void warn(String msg, Throwable throwable) {
337 if (isWarnEnabled()) {
338 error.log(LogLevel.WARN, msg, throwable);
343 public boolean isWarnEnabled(Marker marker) {
348 @Deprecated /** Please use method {@link #warn(EcompLoggerErrorCode, String, String)} **/
349 public void warn(Marker marker, String msg) {
350 if (isWarnEnabled()) {
351 error.log(LogLevel.WARN, msg);
356 @Deprecated /** Please use method {@link #warn(EcompLoggerErrorCode, String, String)} **/
357 public void warn(Marker marker, String msg, Object o) {
358 if (isWarnEnabled()) {
359 error.log(LogLevel.WARN, msg, o);
364 @Deprecated /** Please use method {@link #warn(EcompLoggerErrorCode, String, String)} **/
365 public void warn(Marker marker, String msg, Object o, Object o1) {
366 if (isWarnEnabled()) {
367 error.log(LogLevel.WARN, msg, o, o1);
372 @Deprecated /** Please use method {@link #warn(EcompLoggerErrorCode, String, String)} **/
373 public void warn(Marker marker, String msg, Object... objects) {
374 if (isWarnEnabled()) {
375 error.log(LogLevel.WARN, msg, objects);
380 @Deprecated /** Please use method {@link #warn(EcompLoggerErrorCode, String, String)} **/
381 public void warn(Marker marker, String msg, Throwable throwable) {
382 if (isWarnEnabled()) {
383 error.log(LogLevel.WARN, msg, throwable);
387 @Deprecated /** Please use method {@link #error(EcompLoggerErrorCode, String, String)} **/
388 public void error(String msg, Object... params){
389 if (isErrorEnabled()) {
390 error.log(LogLevel.ERROR, msg, params);
395 @Deprecated /** Please use method {@link #error(EcompLoggerErrorCode, String, String)} **/
396 public void error(String msg, Throwable throwable) {
397 if (isErrorEnabled()) {
398 error.log(LogLevel.ERROR, msg, throwable);
403 public boolean isErrorEnabled(Marker marker) {
408 @Deprecated /** Please use method {@link #error(EcompLoggerErrorCode, String, String)} **/
409 public void error(Marker marker, String msg) {
410 if (isErrorEnabled()) {
411 error.log(LogLevel.ERROR, msg);
416 @Deprecated /** Please use method {@link #error(EcompLoggerErrorCode, String, String)} **/
417 public void error(Marker marker, String msg, Object o) {
418 if (isErrorEnabled()) {
419 error.log(LogLevel.ERROR, msg, o);
424 @Deprecated /** Please use method {@link #error(EcompLoggerErrorCode, String, String)} **/
425 public void error(Marker marker, String msg, Object o, Object o1) {
426 if (isErrorEnabled()) {
427 error.log(LogLevel.ERROR, msg, o, o1);
432 @Deprecated /** Please use method {@link #error(EcompLoggerErrorCode, String, String)} **/
433 public void error(Marker marker, String msg, Object... params) {
434 if (isErrorEnabled()) {
435 error.log(LogLevel.ERROR, msg, params);
440 @Deprecated /** Please use method {@link #error(EcompLoggerErrorCode, String, String)} **/
441 public void error(Marker marker, String msg, Throwable throwable) {
442 if (isErrorEnabled()) {
443 error.log(LogLevel.ERROR, msg, throwable);
447 @Deprecated /** Please use method {@link #error(EcompLoggerErrorCode, String, String)} **/
448 public void error(String msg){
449 if (isErrorEnabled()) {
450 error.log(LogLevel.ERROR, msg);
455 @Deprecated /** Please use method {@link #error(EcompLoggerErrorCode, String, String)} **/
456 public void error(String msg, Object o) {
457 if (isErrorEnabled()) {
458 error.log(LogLevel.ERROR, msg, o);
463 @Deprecated /** Please use method {@link #error(EcompLoggerErrorCode, String, String)} **/
464 public void error(String msg, Object o, Object o1) {
465 if (isErrorEnabled()) {
466 error.log(LogLevel.ERROR, msg, o, o1);
471 * Writes out ERROR logging level message to the application error log
472 * @param errorLevel code representing the error severity level
473 * @param serviceName name of the API invoked at the logging component
474 * @param targetEntity name of the ECOMP component or sub-component, or external entity at which the error occurred or null
475 * @param errorDescription a human readable description of the error condition
476 * @param params optional parameters of a given error description
478 public void error(EcompErrorConfiguration.EcompErrorSeverity errorLevel,
479 EcompLoggerErrorCode errorCodeEnum,
482 String errorDescription, Object...params) {
483 if (isErrorEnabled()) {
484 error.log(errorLevel, errorCodeEnum, serviceName, targetEntity, errorDescription, params);
489 * Writes out ERROR logging level message to the application error log
490 * @param errorCodeEnum code representing the error condition
491 * @param serviceName name of the API invoked at the logging component
492 * @param targetEntity name of the ECOMP component or sub-component, or external entity at which the error occurred or null
493 * @param errorDescription a human readable description of the error condition
494 * @param params optional parameters of a given error description
496 public void error(EcompLoggerErrorCode errorCodeEnum,
499 String errorDescription, Object...params) {
500 if (isErrorEnabled()) {
501 error.log(LogLevel.ERROR, errorCodeEnum, serviceName, targetEntity, errorDescription, params);
506 * Writes out WARN logging level message to the application error log
507 * @param errorCodeEnum code representing the error condition
508 * @param serviceName name of the API invoked at the logging component
509 * @param targetEntity name of the ECOMP component or sub-component, or external entity at which the error occurred or null
510 * @param errorDescription a human readable description of the error condition
511 * @param params optional parameters of a given error description
513 public void warn(EcompLoggerErrorCode errorCodeEnum,
516 String errorDescription, Object...params) {
517 if (isWarnEnabled()) {
518 error.log(LogLevel.WARN, errorCodeEnum, serviceName, targetEntity, errorDescription, params);
523 * Writes out FATAL logging level message to the application error log
524 * @param errorCodeEnum code representing the error condition
525 * @param serviceName name of the API invoked at the logging component
526 * @param targetEntity name of the ECOMP component or sub-component, or external entity at which the error occurred or null
527 * @param errorDescription a human readable description of the error condition
528 * @param params optional parameters of a given error description
530 public void fatal(EcompLoggerErrorCode errorCodeEnum,
533 String errorDescription, Object...params) {
534 if (isErrorEnabled()) {
535 error.log(LogLevel.FATAL, errorCodeEnum, serviceName, targetEntity, errorDescription, params);