Files
openide/jvm/jvm-analysis-kotlin-tests-shared/testData/codeInspection/logging/stringTemplateAsArgument/StringTemplateAsArgumentGuarded.kt
Bart van Helvert 72b748d5e0 [kotlin] Run Kotlin JVM tests on both K1 and K2 frontend
#IDEA-354810 Fixed


(cherry picked from commit d29d3256472dfe368161335732ded20ae95cf34e)

IJ-MR-140910

GitOrigin-RevId: 0a9b3cae7aab473f732012ad91b4e67f97ff8697
2024-08-02 11:11:07 +00:00

70 lines
2.4 KiB
Kotlin

import org.apache.logging.log4j.LogManager
import org.slf4j.LoggerFactory
data class Data(val i: Int)
class StringTemplateAsArgumentGuarded {
private val loggerSlf4J = LoggerFactory.getLogger()
private val loggerLog4J = LogManager.getLogger()
fun guardedLog4J() {
val data = Data(1)
if (loggerLog4J.isInfoEnabled) {
loggerLog4J.info("$data" )
}
if (loggerLog4J.isInfoEnabled()) {
loggerLog4J.info("$data" )
}
loggerLog4J.<warning descr="String template as argument to 'info()' logging call">info</warning>("$data")
}
fun guardedLog4JBuilder() {
val data = Data(1)
val atInfo = loggerLog4J.atInfo()
if (loggerLog4J.isInfoEnabled) {
loggerLog4J.atInfo().log("$data" )
}
if (loggerLog4J.isInfoEnabled) {
atInfo.log("$data" )
}
if (loggerLog4J.isDebugEnabled) {
atInfo.<warning descr="String template as argument to 'log()' logging call">log</warning>("$data" )
}
if (loggerLog4J.isDebugEnabled()) {
atInfo.<warning descr="String template as argument to 'log()' logging call">log</warning>("$data" )
}
loggerLog4J.atInfo().<warning descr="String template as argument to 'log()' logging call">log</warning>("$data" )
atInfo.<warning descr="String template as argument to 'log()' logging call">log</warning>("$data" )
}
fun guardedSlf4j() {
val data = Data(1)
if (loggerSlf4J.isInfoEnabled) {
loggerSlf4J.info("$data" )
}
if (loggerSlf4J.isInfoEnabled()) {
loggerSlf4J.info("$data" )
}
loggerSlf4J.<warning descr="String template as argument to 'info()' logging call">info</warning>("$data")
}
fun guardedSlf4jBuilder() {
val data = Data(1)
val atInfo = loggerSlf4J.atInfo()
if (loggerSlf4J.isInfoEnabled) {
loggerSlf4J.atInfo().log("$data" )
}
if (loggerSlf4J.isInfoEnabled) {
atInfo.log("$data" )
}
if (loggerSlf4J.isDebugEnabled) {
atInfo.<warning descr="String template as argument to 'log()' logging call">log</warning>("$data" )
}
if (loggerSlf4J.isDebugEnabled()) {
atInfo.<warning descr="String template as argument to 'log()' logging call">log</warning>("$data" )
}
loggerSlf4J.atInfo().<warning descr="String template as argument to 'log()' logging call">log</warning>("$data" )
atInfo.<warning descr="String template as argument to 'log()' logging call">log</warning>("$data" )
}
}