2 * ============LICENSE_START=======================================================
3 * dcaegen2-collectors-veshv
4 * ================================================================================
5 * Copyright (C) 2018 NOKIA
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=========================================================
20 package org.onap.dcae.collectors.veshv.utils.logging
22 import kotlin.reflect.KClass
23 import org.slf4j.LoggerFactory
25 @Suppress("TooManyFunctions", "SuboptimalLoggerUsage")
26 class Logger(val logger: org.slf4j.Logger) {
27 constructor(clazz: KClass<out Any>) : this(LoggerFactory.getLogger(clazz.java))
28 constructor(name: String) : this(LoggerFactory.getLogger(name))
34 val traceEnabled: Boolean
35 get() = logger.isTraceEnabled
37 fun trace(messageProvider: () -> String) {
38 if (logger.isTraceEnabled) {
39 logger.trace(messageProvider())
47 fun debug(message: String) {
51 fun debug(message: String, t: Throwable) {
52 logger.debug(message, t)
55 fun debug(messageProvider: () -> String) {
56 if (logger.isDebugEnabled) {
57 logger.debug(messageProvider())
61 fun debug(t: Throwable, messageProvider: () -> String) {
62 if (logger.isDebugEnabled) {
63 logger.debug(messageProvider(), t)
70 fun info(message: String) {
74 fun info(messageProvider: () -> String) {
75 if (logger.isInfoEnabled) {
76 logger.info(messageProvider())
80 fun info(message: String, t: Throwable) {
81 logger.info(message, t)
84 fun info(t: Throwable, messageProvider: () -> String) {
85 if (logger.isInfoEnabled) {
86 logger.info(messageProvider(), t)
94 fun warn(message: String) {
98 fun warn(message: String, t: Throwable) {
99 logger.warn(message, t)
102 fun warn(messageProvider: () -> String) {
103 if (logger.isWarnEnabled) {
104 logger.warn(messageProvider())
108 fun warn(t: Throwable, messageProvider: () -> String) {
109 if (logger.isWarnEnabled) {
110 logger.warn(messageProvider(), t)
118 fun error(message: String) {
119 logger.error(message)
122 fun error(message: String, t: Throwable) {
123 logger.error(message, t)
126 fun error(messageProvider: () -> String) {
127 if (logger.isErrorEnabled) {
128 logger.error(messageProvider())
132 fun error(t: Throwable, messageProvider: () -> String) {
133 if (logger.isErrorEnabled) {
134 logger.error(messageProvider(), t)