1 package org.openecomp.sdc.common.log.wrappers;
3 import com.google.common.annotations.VisibleForTesting;
4 import org.onap.logging.ref.slf4j.ONAPLogConstants;
5 import org.openecomp.sdc.common.log.elements.*;
6 import org.openecomp.sdc.common.log.enums.EcompErrorSeverity;
7 import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode;
8 import org.openecomp.sdc.common.log.enums.LogLevel;
9 import org.slf4j.Marker;
11 import java.util.UUID;
15 * This class wraps {@link org.slf4j.Logger} object and provides mandatory information required by Ecomp logging rules.
16 * Note: All deprecated methods are supported to be compatible to the legacy code
17 * and have not be used by the new code
19 public class Logger implements org.slf4j.Logger {
20 private final LoggerDebug debug;
21 private final LoggerError error;
22 private final LoggerMetric metric;
23 private final org.slf4j.Logger logger;
26 public Logger(org.slf4j.Logger logger) {
28 this.debug = LoggerFactory.getMdcLogger(LoggerDebug.class, logger);
29 this.error = LoggerFactory.getMdcLogger(LoggerError.class, logger);
30 this.metric = LoggerFactory.getMdcLogger(LoggerMetric.class, logger);
34 private Logger(String className) {
35 this(org.slf4j.LoggerFactory.getLogger(className));
38 public static Logger getLogger(String className) {
39 return new Logger(className);
42 public static Logger getLogger(Class<?> clazz) {
43 return new Logger(clazz.getName());
47 public boolean isDebugEnabled() {
48 return logger.isDebugEnabled();
52 public String getName() {
53 return logger.getName();
56 public boolean isTraceEnabled() {
57 return logger.isTraceEnabled();
60 public boolean isErrorEnabled() { return logger.isErrorEnabled(); }
62 public boolean isWarnEnabled() { return logger.isWarnEnabled(); }
65 @Deprecated /** Please use method {@link #warn(EcompLoggerErrorCode, String, String)} **/
66 public void warn(String msg) {
67 if (isWarnEnabled()) {
68 error.log(LogLevel.WARN, msg);
73 @Deprecated /** Please use method {@link #warn(EcompLoggerErrorCode, String, String)} **/
74 public void warn(String msg, Object o) {
76 if (isWarnEnabled()) {
77 error.log(LogLevel.WARN, msg, o);
81 public boolean isInfoEnabled() { return logger.isInfoEnabled(); }
84 public void info(String msg) {
85 if (isInfoEnabled()) {
86 debug.log(LogLevel.INFO, msg);
91 public void info(String msg, Object o) {
92 if (isInfoEnabled()) {
93 debug.log(LogLevel.INFO, msg, o);
98 public void info(String msg, Object o, Object o1) {
99 if (isInfoEnabled()) {
100 debug.log(LogLevel.INFO, msg, o, o1);
104 public void debug(String msg, Object... params) {
105 if (isDebugEnabled()) {
106 debug.log(LogLevel.DEBUG, msg, params);
110 public void metric(String msg, Object... params) {
111 metric.log(LogLevel.INFO, msg, params);
114 public void invoke(String targetEntity, String targetServiceName, String serviceName, String msg, Object... params) {
116 String invocationId = UUID.randomUUID().toString();
117 String requestID = UUID.randomUUID().toString();
121 .setOutgoingInvocationId(invocationId)
122 .setTargetServiceName(targetServiceName)
123 .setTargetEntity(targetEntity)
124 .setStatusCode(ONAPLogConstants.ResponseStatus.COMPLETE.name())
125 .setKeyRequestId(requestID)
126 .setServiceName(serviceName);
127 metric.log(ONAPLogConstants.Markers.INVOKE, LogLevel.INFO, msg, params);
130 public void invokeReturn(String msg, Object... params) {
134 } catch (Exception e) {
137 metric.log(ONAPLogConstants.Markers.INVOKE_RETURN, LogLevel.INFO, msg, params);
140 public void invokeSynchronous(String msg, Object... params) {
141 metric.log(ONAPLogConstants.Markers.INVOKE_SYNCHRONOUS, LogLevel.INFO, msg, params);
145 public void debug(String msg, Throwable throwable) {
146 if (isDebugEnabled()) {
147 debug.log(LogLevel.DEBUG, msg, throwable);
152 public boolean isDebugEnabled(Marker marker) {
157 public void debug(Marker marker, String msg) {
158 if (isDebugEnabled()) {
159 debug.log(LogLevel.DEBUG, msg);
164 public void debug(Marker marker, String msg, Object o) {
165 if (isDebugEnabled()) {
166 debug.log(LogLevel.DEBUG, msg, o);
171 public void debug(Marker marker, String msg, Object o, Object o1) {
172 if (isDebugEnabled()) {
173 debug.log(LogLevel.DEBUG, msg, o, o1);
178 public void debug(Marker marker, String msg, Object... objects) {
179 if (isDebugEnabled()) {
180 debug.log(LogLevel.DEBUG, msg, objects);
185 public void debug(Marker marker, String msg, Throwable throwable) {
186 if (isDebugEnabled()) {
187 debug.log(LogLevel.DEBUG, msg, throwable);
191 public void debug(String message) {
192 if (isDebugEnabled()) {
193 debug.log(LogLevel.DEBUG, message);
198 public void debug(String msg, Object o) {
199 if (isDebugEnabled()) {
200 debug.log(LogLevel.DEBUG, msg, o);
205 public void debug(String msg, Object o, Object o1) {
206 if (isDebugEnabled()) {
207 debug.log(LogLevel.DEBUG, msg, o, o1);
211 public void trace(String message, Object... params) {
212 if (isTraceEnabled()) {
213 debug.log(LogLevel.TRACE, message, params);
218 public void trace(String msg, Throwable throwable) {
219 if (isTraceEnabled()) {
220 debug.log(LogLevel.TRACE, msg, throwable);
225 public boolean isTraceEnabled(Marker marker) {
230 public void trace(Marker marker, String msg) {
231 if (isTraceEnabled()) {
232 debug.log(LogLevel.TRACE, msg);
237 public void trace(Marker marker, String msg, Object o) {
238 if (isTraceEnabled()) {
239 debug.log(LogLevel.TRACE, msg, o);
244 public void trace(Marker marker, String msg, Object o, Object o1) {
245 if (isTraceEnabled()) {
246 debug.log(LogLevel.TRACE, msg, o, o1);
251 public void trace(Marker marker, String msg, Object... objects) {
252 if (isTraceEnabled()) {
253 debug.log(LogLevel.TRACE, msg, objects);
258 public void trace(Marker marker, String msg, Throwable throwable) {
259 if (isTraceEnabled()) {
260 debug.log(LogLevel.TRACE, msg, throwable);
264 public void trace(String msg) {
265 if (isTraceEnabled()) {
266 debug.log(LogLevel.TRACE, msg);
271 public void trace(String msg, Object o) {
272 if (isTraceEnabled()) {
273 debug.log(LogLevel.TRACE, msg, o);
278 public void trace(String msg, Object o, Object o1) {
279 if (isTraceEnabled()) {
280 debug.log(LogLevel.TRACE, msg, o, o1);
284 public void info(String msg, Object... params) {
285 if (isInfoEnabled()) {
286 debug.log(LogLevel.INFO, msg, params);
291 public void info(String msg, Throwable throwable) {
292 if (isInfoEnabled()) {
293 debug.log(LogLevel.INFO, msg, throwable);
298 public boolean isInfoEnabled(Marker marker) {
303 public void info(Marker marker, String msg) {
304 if (isInfoEnabled()) {
305 debug.log(LogLevel.INFO, msg);
310 public void info(Marker marker, String msg, Object o) {
311 if (isInfoEnabled()) {
312 debug.log(LogLevel.INFO, msg, o);
317 public void info(Marker marker, String msg, Object o, Object o1) {
318 if (isInfoEnabled()) {
319 debug.log(LogLevel.INFO, msg, o, o1);
324 public void info(Marker marker, String msg, Object... objects) {
325 if (isInfoEnabled()) {
326 debug.log(LogLevel.INFO, msg, objects);
331 public void info(Marker marker, String msg, Throwable throwable) {
332 if (isInfoEnabled()) {
333 debug.log(LogLevel.INFO, msg, throwable);
337 @Deprecated /** Please use method {@link #warn(EcompLoggerErrorCode, String, String)} **/
338 public void warn(String msg, Object... params){
339 if (isWarnEnabled()) {
340 error.log(LogLevel.WARN, msg, params);
345 @Deprecated /** Please use method {@link #warn(EcompLoggerErrorCode, String, String)} **/
346 public void warn(String msg, Object o, Object o1) {
347 if (isWarnEnabled()) {
348 error.log(LogLevel.WARN, msg, o, o1);
353 @Deprecated /** Please use method {@link #warn(EcompLoggerErrorCode, String, String)} **/
354 public void warn(String msg, Throwable throwable) {
355 if (isWarnEnabled()) {
356 error.log(LogLevel.WARN, msg, throwable);
361 public boolean isWarnEnabled(Marker marker) {
366 @Deprecated /** Please use method {@link #warn(EcompLoggerErrorCode, String, String)} **/
367 public void warn(Marker marker, String msg) {
368 if (isWarnEnabled()) {
369 error.log(LogLevel.WARN, msg);
374 @Deprecated /** Please use method {@link #warn(EcompLoggerErrorCode, String, String)} **/
375 public void warn(Marker marker, String msg, Object o) {
376 if (isWarnEnabled()) {
377 error.log(LogLevel.WARN, msg, o);
382 @Deprecated /** Please use method {@link #warn(EcompLoggerErrorCode, String, String)} **/
383 public void warn(Marker marker, String msg, Object o, Object o1) {
384 if (isWarnEnabled()) {
385 error.log(LogLevel.WARN, msg, o, o1);
390 @Deprecated /** Please use method {@link #warn(EcompLoggerErrorCode, String, String)} **/
391 public void warn(Marker marker, String msg, Object... objects) {
392 if (isWarnEnabled()) {
393 error.log(LogLevel.WARN, msg, objects);
398 @Deprecated /** Please use method {@link #warn(EcompLoggerErrorCode, String, String)} **/
399 public void warn(Marker marker, String msg, Throwable throwable) {
400 if (isWarnEnabled()) {
401 error.log(LogLevel.WARN, msg, throwable);
405 @Deprecated /** Please use method {@link #error(EcompLoggerErrorCode, String, String)} **/
406 public void error(String msg, Object... params){
407 if (isErrorEnabled()) {
408 error.log(LogLevel.ERROR, msg, params);
413 @Deprecated /** Please use method {@link #error(EcompLoggerErrorCode, String, String)} **/
414 public void error(String msg, Throwable throwable) {
415 if (isErrorEnabled()) {
416 error.log(LogLevel.ERROR, msg, throwable);
421 public boolean isErrorEnabled(Marker marker) {
426 @Deprecated /** Please use method {@link #error(EcompLoggerErrorCode, String, String)} **/
427 public void error(Marker marker, String msg) {
428 if (isErrorEnabled()) {
429 error.log(LogLevel.ERROR, msg);
434 @Deprecated /** Please use method {@link #error(EcompLoggerErrorCode, String, String)} **/
435 public void error(Marker marker, String msg, Object o) {
436 if (isErrorEnabled()) {
437 error.log(LogLevel.ERROR, msg, o);
442 @Deprecated /** Please use method {@link #error(EcompLoggerErrorCode, String, String)} **/
443 public void error(Marker marker, String msg, Object o, Object o1) {
444 if (isErrorEnabled()) {
445 error.log(LogLevel.ERROR, msg, o, o1);
450 @Deprecated /** Please use method {@link #error(EcompLoggerErrorCode, String, String)} **/
451 public void error(Marker marker, String msg, Object... params) {
452 if (isErrorEnabled()) {
453 error.log(LogLevel.ERROR, msg, params);
458 @Deprecated /** Please use method {@link #error(EcompLoggerErrorCode, String, String)} **/
459 public void error(Marker marker, String msg, Throwable throwable) {
460 if (isErrorEnabled()) {
461 error.log(LogLevel.ERROR, msg, throwable);
465 @Deprecated /** Please use method {@link #error(EcompLoggerErrorCode, String, String)} **/
466 public void error(String msg){
467 if (isErrorEnabled()) {
468 error.log(LogLevel.ERROR, msg);
473 @Deprecated /** Please use method {@link #error(EcompLoggerErrorCode, String, String)} **/
474 public void error(String msg, Object o) {
475 if (isErrorEnabled()) {
476 error.log(LogLevel.ERROR, msg, o);
481 @Deprecated /** Please use method {@link #error(EcompLoggerErrorCode, String, String)} **/
482 public void error(String msg, Object o, Object o1) {
483 if (isErrorEnabled()) {
484 error.log(LogLevel.ERROR, msg, o, o1);
489 * Writes out ERROR logging level message to the application error log
490 * @param errorLevel code representing the error severity level
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(EcompErrorSeverity errorLevel,
497 EcompLoggerErrorCode errorCodeEnum,
500 String errorDescription, Object...params) {
501 if (isErrorEnabled()) {
502 error.log(errorLevel, errorCodeEnum, serviceName, targetEntity, errorDescription, params);
507 * Writes out ERROR logging level message to the application error log
508 * @param errorCodeEnum code representing the error condition
509 * @param serviceName name of the API invoked at the logging component
510 * @param targetEntity name of the ECOMP component or sub-component, or external entity at which the error occurred or null
511 * @param errorDescription a human readable description of the error condition
512 * @param params optional parameters of a given error description
514 @Deprecated /** Please use method {@link #error(EcompLoggerErrorCode, String, ErrorLogOptionalData, String, Object...)} **/
515 public void error(EcompLoggerErrorCode errorCodeEnum,
518 String errorDescription, Object...params) {
519 if (isErrorEnabled()) {
520 error.log(LogLevel.ERROR, errorCodeEnum, serviceName, targetEntity, errorDescription, params);
524 /* Writes out ERROR logging level message to the application error LOG
525 * @param errorCodeEnum code representing the error condition
526 * @param errorDescription a human readable description of the error condition
527 * @param params optional parameters of a given error description
530 public void error(EcompLoggerErrorCode errorCodeEnum, String serviceName,
531 String errorDescription, Object...params) {
532 error(errorCodeEnum, serviceName, (String)null, errorDescription, params);
536 * Writes out ERROR logging level message to the application error log
537 * @param errorCodeEnum code representing the error condition
538 * @param serviceName name of the API invoked at the logging component
539 * @param errorLogOptionalData elements that contans all relevant data of the error
540 * @param errorDescription a human readable description of the error condition
541 * @param params optional parameters of a given error description
543 public void error(EcompLoggerErrorCode errorCodeEnum,
545 ErrorLogOptionalData errorLogOptionalData,
546 String errorDescription,
548 if (isErrorEnabled()) {
549 error.log(LogLevel.ERROR, errorCodeEnum, serviceName, errorLogOptionalData, errorDescription, params);
554 * Writes out WARN logging level message to the application error log
555 * @param errorCodeEnum code representing the error condition
556 * @param serviceName name of the API invoked at the logging component
557 * @param targetEntity name of the ECOMP component or sub-component, or external entity at which the error occurred or null
558 * @param errorDescription a human readable description of the error condition
559 * @param params optional parameters of a given error description
561 public void warn(EcompLoggerErrorCode errorCodeEnum,
564 String errorDescription, Object...params) {
565 if (isWarnEnabled()) {
566 error.log(LogLevel.WARN, errorCodeEnum, serviceName, targetEntity, errorDescription, params);
571 * Writes out WARN logging level message to the application error log
572 * @param errorCodeEnum code representing the error condition
573 * @param serviceName name of the API invoked at the logging component
574 * @param errorLogOptionalData elements that contans all relevant data of the error
575 * @param description a human readable description of the error condition
576 * @param params optional parameters of a given error description
578 public void warn(EcompLoggerErrorCode errorCodeEnum,
580 ErrorLogOptionalData errorLogOptionalData,
581 String description, Object...params) {
582 if (isWarnEnabled()) {
583 error.log(LogLevel.WARN, errorCodeEnum, serviceName, errorLogOptionalData, description, params);
588 * Writes out WARN logging level message to the application error log
589 * @param errorCodeEnum code representing the error condition
590 * @param serviceName name of the API invoked at the logging component
591 * @param errorDescription a human readable description of the error condition
592 * @param params optional parameters of a given error description
594 public void warn(EcompLoggerErrorCode errorCodeEnum,
596 String errorDescription, Object...params) {
597 if (isWarnEnabled()) {
598 error.log(LogLevel.WARN, errorCodeEnum, serviceName, (String)null, errorDescription, params);
603 * Writes out FATAL logging level message to the application error log
604 * @param errorCodeEnum code representing the error condition
605 * @param serviceName name of the API invoked at the logging component
606 * @param targetEntity name of the ECOMP component or sub-component, or external entity at which the error occurred or null
607 * @param errorDescription a human readable description of the error condition
608 * @param params optional parameters of a given error description
610 public void fatal(EcompLoggerErrorCode errorCodeEnum,
613 String errorDescription, Object...params) {
614 if (isErrorEnabled()) {
615 error.log(LogLevel.FATAL, errorCodeEnum, serviceName, targetEntity, errorDescription, params);
620 * Writes out FATAL logging level message to the application error log
621 * @param errorCodeEnum code representing the error condition
622 * @param serviceName name of the API invoked at the logging component
623 * @param errorLogOptionalData elements that contans all relevant data of the error
624 * @param description a human readable description of the error condition
625 * @param params optional parameters of a given error description
627 public void fatal(EcompLoggerErrorCode errorCodeEnum, String serviceName,
628 ErrorLogOptionalData errorLogOptionalData,
629 String description, Object...params) {
630 if (isErrorEnabled()) {
631 error.log(LogLevel.FATAL, errorCodeEnum, serviceName, errorLogOptionalData, description, params);