Bump checkstyle version
[dcaegen2/collectors/hv-ves.git] / sources / hv-collector-utils / src / main / kotlin / org / onap / dcae / collectors / veshv / utils / logging / Logger.kt
1 /*
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20 package org.onap.dcae.collectors.veshv.utils.logging
21
22 import kotlin.reflect.KClass
23 import org.slf4j.LoggerFactory
24
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))
29
30     //
31     // TRACE
32     //
33
34     val traceEnabled: Boolean
35         get() = logger.isTraceEnabled
36
37     fun trace(messageProvider: () -> String) {
38         if (logger.isTraceEnabled) {
39             logger.trace(messageProvider())
40         }
41     }
42
43     //
44     // DEBUG
45     //
46
47     fun debug(message: String) {
48         logger.debug(message)
49     }
50
51     fun debug(message: String, t: Throwable) {
52         logger.debug(message, t)
53     }
54
55     fun debug(messageProvider: () -> String) {
56         if (logger.isDebugEnabled) {
57             logger.debug(messageProvider())
58         }
59     }
60
61     fun debug(t: Throwable, messageProvider: () -> String) {
62         if (logger.isDebugEnabled) {
63             logger.debug(messageProvider(), t)
64         }
65     }
66
67     //
68     // INFO
69     //
70     fun info(message: String) {
71         logger.info(message)
72     }
73
74     fun info(messageProvider: () -> String) {
75         if (logger.isInfoEnabled) {
76             logger.info(messageProvider())
77         }
78     }
79
80     fun info(message: String, t: Throwable) {
81         logger.info(message, t)
82     }
83
84     fun info(t: Throwable, messageProvider: () -> String) {
85         if (logger.isInfoEnabled) {
86             logger.info(messageProvider(), t)
87         }
88     }
89
90     //
91     // WARN
92     //
93
94     fun warn(message: String) {
95         logger.warn(message)
96     }
97
98     fun warn(message: String, t: Throwable) {
99         logger.warn(message, t)
100     }
101
102     fun warn(messageProvider: () -> String) {
103         if (logger.isWarnEnabled) {
104             logger.warn(messageProvider())
105         }
106     }
107
108     fun warn(t: Throwable, messageProvider: () -> String) {
109         if (logger.isWarnEnabled) {
110             logger.warn(messageProvider(), t)
111         }
112     }
113
114     //
115     // ERROR
116     //
117
118     fun error(message: String) {
119         logger.error(message)
120     }
121
122     fun error(message: String, t: Throwable) {
123         logger.error(message, t)
124     }
125
126     fun error(messageProvider: () -> String) {
127         if (logger.isErrorEnabled) {
128             logger.error(messageProvider())
129         }
130     }
131
132     fun error(t: Throwable, messageProvider: () -> String) {
133         if (logger.isErrorEnabled) {
134             logger.error(messageProvider(), t)
135         }
136     }
137 }