2 * ================================================================================
3 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 * ============LICENSE_END=========================================================
20 package org.onap.dcae.utils.eelf.logger.logback.log;
23 import org.onap.dcae.utils.eelf.logger.api.info.LogLevelCategory;
24 import org.onap.dcae.utils.eelf.logger.api.log.DebugLog;
25 import org.onap.dcae.utils.eelf.logger.api.spec.DebugLogSpec;
26 import org.onap.dcae.utils.eelf.logger.api.spec.OptionalLogSpec;
27 import org.onap.dcae.utils.eelf.logger.logback.utils.LogUtils;
28 import org.slf4j.Logger;
32 * Debug Log Logback Implementation
34 * @author Rajiv Singla
36 public class DebugLogImpl implements DebugLog {
38 private final Logger logger;
39 private final Class<?> clazz;
41 public DebugLogImpl(final Logger logger, final Class<?> clazz) {
47 public void log(final LogLevelCategory logLevelCategory, final String message, final DebugLogSpec debugLogSpec,
48 final OptionalLogSpec optionalLogSpec, final String... args) {
50 // if log level category is null throw an exception
51 if (logLevelCategory == null) {
52 throw new IllegalArgumentException("Log level category must not be null");
55 LogUtils.CUSTOM_MDC_MAP.put(LogUtils.LOG_LEVEL_CATEGORY_KEY, logLevelCategory);
56 LogUtils.CUSTOM_MDC_MAP.put(LogUtils.DEBUG_LOG_SPEC_KEY, debugLogSpec);
57 LogUtils.CUSTOM_MDC_MAP.put(LogUtils.LOGGER_CLASS_KEY, clazz);
59 LogUtils.CUSTOM_MDC_MAP.put(LogUtils.OPTIONAL_LOG_SPEC_KEY, optionalLogSpec);
61 // log with normalized log level category
62 LogUtils.logWithLogLevel(logLevelCategory, logger, LogUtils.DEBUG_LOG_MARKER, message, args);
65 LogUtils.CUSTOM_MDC_MAP.remove(LogUtils.LOG_LEVEL_CATEGORY_KEY);
66 LogUtils.CUSTOM_MDC_MAP.remove(LogUtils.DEBUG_LOG_SPEC_KEY);
67 LogUtils.CUSTOM_MDC_MAP.remove(LogUtils.LOGGER_CLASS_KEY);
68 LogUtils.CUSTOM_MDC_MAP.remove(LogUtils.OPTIONAL_LOG_SPEC_KEY);
73 public void log(final LogLevelCategory logLevelCategory, final String message, final DebugLogSpec debugLogSpec,
74 final String... args) {
75 log(logLevelCategory, message, debugLogSpec, null, args);
79 public void debug(final String message, final DebugLogSpec debugLogSpec, final OptionalLogSpec optionalLogSpec,
80 final String... args) {
81 log(LogLevelCategory.DEBUG, message, debugLogSpec, optionalLogSpec, args);
85 public void debug(final String message, final DebugLogSpec debugLogSpec, final String... args) {
86 debug(message, debugLogSpec, null, args);