From 222290dbf229678bbe0685f35af60d3fb3c59570 Mon Sep 17 00:00:00 2001 From: oshai Date: Wed, 24 Jan 2018 10:43:33 +0100 Subject: [PATCH] Multiplatform (#35) * issue #21 - make the lib multiplatform - split to common/jvm/js - left all code in jvm at the moment - add build scripts * issue #31 - Add MDC support: withLoggingContext * merge to branch: issue #31 - Add MDC support: withLoggingContext * add documentation * rebase (#33) * issue #31 - Add MDC support: withLoggingContext * Update ChangleLog.md * Update ChangleLog.md * Update README.md * Rename ChangleLog.md to ChangeLog.md (#32) * update to kotlin 1.2.20 * split packages and gradle build * split packages and gradle build * split packages and gradle build * fix src root for jvm project * fix artifact build for jvm version --- build.gradle | 192 +++++++++--------- kotlin-logging-common/build.gradle | 9 + kotlin-logging-js/build.gradle | 27 +++ kotlin-logging-jvm/build.gradle | 41 ++++ .../src/main/kotlin/mu/KLogger.kt | 87 ++++++++ .../src}/main/kotlin/mu/KLogging.kt | 0 .../src}/main/kotlin/mu/KotlinLogging.kt | 0 .../src/main/kotlin/mu/KotlinLoggingMDC.kt | 42 ++++ .../main/kotlin/mu/internal/KLoggerFactory.kt | 0 .../kotlin/mu/internal/KLoggerNameResolver.kt | 0 .../mu/internal/LocationAwareKLogger.kt | 0 .../mu/internal/LocationIgnorantKLogger.kt | 0 .../main/kotlin/mu/internal/MessageInvoker.kt | 0 .../mu/ClassWithLoggingForLocationTesting.kt | 0 .../test/kotlin/mu/KotlinLoggingMDCTest.kt | 41 ++++ .../src}/test/kotlin/mu/KotlinLoggingTest.kt | 0 .../src}/test/kotlin/mu/LoggingTest.kt | 0 .../test/kotlin/mu/LoggingWithLocationTest.kt | 0 .../mu/internal/KLoggerNameResolverTest.kt | 0 .../src}/test/resources/log4j.properties | 0 settings.gradle | 5 +- src/main/kotlin/mu/KLogger.kt | 87 -------- versions.gradle | 2 + 23 files changed, 349 insertions(+), 184 deletions(-) create mode 100644 kotlin-logging-common/build.gradle create mode 100644 kotlin-logging-js/build.gradle create mode 100644 kotlin-logging-jvm/build.gradle create mode 100644 kotlin-logging-jvm/src/main/kotlin/mu/KLogger.kt rename {src => kotlin-logging-jvm/src}/main/kotlin/mu/KLogging.kt (100%) rename {src => kotlin-logging-jvm/src}/main/kotlin/mu/KotlinLogging.kt (100%) create mode 100644 kotlin-logging-jvm/src/main/kotlin/mu/KotlinLoggingMDC.kt rename {src => kotlin-logging-jvm/src}/main/kotlin/mu/internal/KLoggerFactory.kt (100%) rename {src => kotlin-logging-jvm/src}/main/kotlin/mu/internal/KLoggerNameResolver.kt (100%) rename {src => kotlin-logging-jvm/src}/main/kotlin/mu/internal/LocationAwareKLogger.kt (100%) rename {src => kotlin-logging-jvm/src}/main/kotlin/mu/internal/LocationIgnorantKLogger.kt (100%) rename {src => kotlin-logging-jvm/src}/main/kotlin/mu/internal/MessageInvoker.kt (100%) rename {src => kotlin-logging-jvm/src}/test/kotlin/mu/ClassWithLoggingForLocationTesting.kt (100%) create mode 100644 kotlin-logging-jvm/src/test/kotlin/mu/KotlinLoggingMDCTest.kt rename {src => kotlin-logging-jvm/src}/test/kotlin/mu/KotlinLoggingTest.kt (100%) rename {src => kotlin-logging-jvm/src}/test/kotlin/mu/LoggingTest.kt (100%) rename {src => kotlin-logging-jvm/src}/test/kotlin/mu/LoggingWithLocationTest.kt (100%) rename {src => kotlin-logging-jvm/src}/test/kotlin/mu/internal/KLoggerNameResolverTest.kt (100%) rename {src => kotlin-logging-jvm/src}/test/resources/log4j.properties (100%) delete mode 100644 src/main/kotlin/mu/KLogger.kt create mode 100644 versions.gradle diff --git a/build.gradle b/build.gradle index 8ffa2e6d..59565de9 100644 --- a/build.gradle +++ b/build.gradle @@ -1,128 +1,130 @@ buildscript { - ext.kotlin_version = '1.2.10' + apply from: 'versions.gradle' repositories { mavenCentral() + jcenter() } + dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3' } } -plugins { - id "com.jfrog.bintray" version "1.7" +allprojects { + group 'io.github.microutils' + version '1.5.3' + + repositories { + mavenCentral() + } } -group 'MicroUtils' -version '1.4.8' +apply plugin: 'kotlin' +subprojects { + apply plugin: 'maven-publish' + apply plugin: 'com.jfrog.bintray' + def varintName = "kotlin-logging" -apply plugin: 'kotlin' -// Apply the java plugin to add support for Java -apply plugin: 'java' -apply plugin: 'maven' -apply plugin: 'maven-publish' -sourceCompatibility = 1.6 - -repositories { - mavenCentral() -} + if (project.name != "kotlin-logging-jvm") { + varintName = "${project.name}" + } -dependencies { - compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" - compile "org.slf4j:slf4j-api:1.7.25" - testCompile "org.slf4j:slf4j-log4j12:1.7.25" - testCompile "log4j:log4j:1.2.17" - testCompile "org.mockito:mockito-all:1.10.19" - testCompile 'junit:junit:4.12' -} + afterEvaluate { + task sourceJar(type: Jar, dependsOn: classes) { + classifier 'sources' + from sourceSets.main.kotlin + duplicatesStrategy = "exclude" + def platformSrc = sourceSets.main.kotlin + def commonSrc = project(':kotlin-logging-common').sourceSets.main.kotlin + from (platformSrc + commonSrc) + } -//https://github.com/bintray/gradle-bintray-plugin -bintray { - user = 'oshai' - key = 'my_key' //https://bintray.com/profile/edit - publications = ['MyPublication'] - pkg { - repo = 'kotlin-logging' - name = 'kotlin-logging' - userOrg = 'microutils' - licenses = ['Apache-2.0'] - vcsUrl = 'https://github.com/MicroUtils/kotlin-logging' - version { - name = '1.4.8' - desc = "kotlin-logging 1.4.8 - Lightweight logging framework for Kotlin" - released = new Date() + task javadocJar(type: Jar, dependsOn: javadoc) { + classifier = 'javadoc' + from javadoc.destinationDir } } -} -// kotlin compiler compatibility options -compileKotlin { - kotlinOptions { - apiVersion = "1.0" - languageVersion = "1.0" + tasks.withType(Jar) { + archivesBaseName = varintName } -} - -// custom tasks for creating source/javadoc jars -task sourcesJar(type: Jar, dependsOn: classes) { - classifier = 'sources' - from sourceSets.main.allSource -} - -task javadocJar(type: Jar, dependsOn: javadoc) { - classifier = 'javadoc' - from javadoc.destinationDir -} -// add javadoc/source jar tasks as artifacts -artifacts { - archives sourcesJar, javadocJar -} + def pomConfig = { + name "kotlin-logging" + description "kotlin-logging $version - Lightweight logging framework for Kotlin" + url "https://github.com/MicroUtils/kotlin-logging" -def pomConfig = { - name "kotlin-logging" - description "kotlin-logging $version - Lightweight logging framework for Kotlin" - url "https://github.com/MicroUtils/kotlin-logging" - - scm { - url "http://github.com/MicroUtils/kotlin-logging/tree/master" - connection "scm:git:git://github.com/MicroUtils/kotlin-logging.git" - developerConnection "scm:git:ssh://github.com:MicroUtils/kotlin-logging.git" - } - licenses { - license { - name "The Apache Software License, Version 2.0" - url "http://www.apache.org/licenses/LICENSE-2.0.txt" + scm { + url "http://github.com/MicroUtils/kotlin-logging/tree/master" + connection "scm:git:git://github.com/MicroUtils/kotlin-logging.git" + developerConnection "scm:git:ssh://github.com:MicroUtils/kotlin-logging.git" } - } - developers { - developer { - name "Ohad Shai" - email "ohadshai@gmail.com" - organization "github" - organizationUrl "http://www.github.com" + licenses { + license { + name "The Apache Software License, Version 2.0" + url "http://www.apache.org/licenses/LICENSE-2.0.txt" + } + } + developers { + developer { + name "Ohad Shai" + email "ohadshai@gmail.com" + organization "github" + organizationUrl "http://www.github.com" + } } } -} -publishing { - publications { - MyPublication(MavenPublication) { - pom.withXml { - def root = asNode() - root.appendNode('description', "kotlin-logging $version - Lightweight logging framework for Kotlin") - root.children().last() + pomConfig + publishing { + publications { + mavenProject(MavenPublication) { + from components.java + groupId project.group + artifactId varintName + version project.version + + pom.withXml { + def root = asNode() + root.appendNode('description', "kotlin-logging $version - Lightweight logging framework for Kotlin") + root.children().last() + pomConfig + } + + + artifact sourceJar { + classifier "sources" + } + artifact javadocJar { + classifier "javadoc" + } } - from components.java - groupId 'io.github.microutils' - artifactId 'kotlin-logging' - version version + } + } - artifact sourcesJar - artifact javadocJar + bintray { + user = 'oshai'//project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('BINTRAY_USER') + key = 'mykey' //https://bintray.com/profile/edit + // project.hasProperty('bintrayApiKey') ? project.property('bintrayApiKey') : System.getenv('BINTRAY_API_KEY') + publications = ['mavenProject'] + pkg { + repo = 'kotlin-logging' + name = 'kotlin-logging' + userOrg = 'microutils' + licenses = ['Apache-2.0'] + vcsUrl = 'https://github.com/MicroUtils/kotlin-logging' + websiteUrl = 'https://github.com/MicroUtils/kotlin-logging' + issueTrackerUrl = 'https://github.com/MicroUtils/kotlin-logging/issues' + + githubRepo = 'MicroUtils/kotlin-logging' + version { + name = project.version + desc = "kotlin-logging - Lightweight logging framework for Kotlin" + released = new Date() + } } } } diff --git a/kotlin-logging-common/build.gradle b/kotlin-logging-common/build.gradle new file mode 100644 index 00000000..17286046 --- /dev/null +++ b/kotlin-logging-common/build.gradle @@ -0,0 +1,9 @@ +apply plugin: 'kotlin-platform-common' + +repositories { + mavenCentral() +} + +dependencies { + compile "org.jetbrains.kotlin:kotlin-stdlib-common:$kotlin_version" +} diff --git a/kotlin-logging-js/build.gradle b/kotlin-logging-js/build.gradle new file mode 100644 index 00000000..550c7bd7 --- /dev/null +++ b/kotlin-logging-js/build.gradle @@ -0,0 +1,27 @@ +apply plugin: 'kotlin-platform-js' + +repositories { + mavenCentral() +} + +sourceSets { + main { + kotlin { + srcDirs = ['src', '../kotlin-logging-common/src'] + } + } +} + +dependencies { + compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version" + expectedBy project(':kotlin-logging-common') +} + +def target = "${projectDir}/build/classes/main" + +compileKotlin2Js { + kotlinOptions.metaInfo = true + kotlinOptions.outputFile = "$target/kotlin-logging.js" + kotlinOptions.sourceMap = true + kotlinOptions.moduleKind = 'umd' +} diff --git a/kotlin-logging-jvm/build.gradle b/kotlin-logging-jvm/build.gradle new file mode 100644 index 00000000..2db777b2 --- /dev/null +++ b/kotlin-logging-jvm/build.gradle @@ -0,0 +1,41 @@ +apply plugin: 'kotlin-platform-jvm' + +buildscript { + + repositories { + mavenCentral() + } + dependencies { + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + } +} +sourceCompatibility = 1.6 + +compileKotlin { + kotlinOptions.jvmTarget = "1.6" +} + +repositories { + mavenCentral() +} + +dependencies { + expectedBy project(':kotlin-logging-common') + compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" + compile "org.slf4j:slf4j-api:$sl4j_version" + testCompile "org.slf4j:slf4j-log4j12:$sl4j_version" + testCompile "log4j:log4j:1.2.17" + testCompile "org.mockito:mockito-all:1.10.19" + testCompile 'junit:junit:4.12' +} + +// kotlin compiler compatibility options +compileKotlin { + kotlinOptions { + apiVersion = "1.0" + languageVersion = "1.0" + } +} + + + diff --git a/kotlin-logging-jvm/src/main/kotlin/mu/KLogger.kt b/kotlin-logging-jvm/src/main/kotlin/mu/KLogger.kt new file mode 100644 index 00000000..e58eeca8 --- /dev/null +++ b/kotlin-logging-jvm/src/main/kotlin/mu/KLogger.kt @@ -0,0 +1,87 @@ +package mu + +import mu.internal.toStringSafe +import org.slf4j.Logger + +/** + * An extension for [Logger] with Lazy message evaluation + * example: + * logger.info{"this is $lazy evaluated string"} + */ +interface KLogger : Logger { + + /** + * The actual logger executing logging + */ + val underlyingLogger: Logger + + /** + * Lazy add a log message if isTraceEnabled is true + */ + fun trace(msg: () -> Any?) { + if (isTraceEnabled) trace(msg.toStringSafe()) + } + + /** + * Lazy add a log message if isDebugEnabled is true + */ + fun debug(msg: () -> Any?) { + if (isDebugEnabled) debug(msg.toStringSafe()) + } + + /** + * Lazy add a log message if isInfoEnabled is true + */ + fun info(msg: () -> Any?) { + if (isInfoEnabled) info(msg.toStringSafe()) + } + + /** + * Lazy add a log message if isWarnEnabled is true + */ + fun warn(msg: () -> Any?) { + if (isWarnEnabled) warn(msg.toStringSafe()) + } + + /** + * Lazy add a log message if isErrorEnabled is true + */ + fun error(msg: () -> Any?) { + if (isErrorEnabled) error(msg.toStringSafe()) + } + + /** + * Lazy add a log message with throwable payload if isTraceEnabled is true + */ + fun trace(t: Throwable, msg: () -> Any?) { + if (isTraceEnabled) trace(msg.toStringSafe(), t) + } + + /** + * Lazy add a log message with throwable payload if isDebugEnabled is true + */ + fun debug(t: Throwable, msg: () -> Any?) { + if (isDebugEnabled) debug(msg.toStringSafe(), t) + } + + /** + * Lazy add a log message with throwable payload if isInfoEnabled is true + */ + fun info(t: Throwable, msg: () -> Any?) { + if (isInfoEnabled) info(msg.toStringSafe(), t) + } + + /** + * Lazy add a log message with throwable payload if isWarnEnabled is true + */ + fun warn(t: Throwable, msg: () -> Any?) { + if (isWarnEnabled) warn(msg.toStringSafe(), t) + } + + /** + * Lazy add a log message with throwable payload if isErrorEnabled is true + */ + fun error(t: Throwable, msg: () -> Any?) { + if (isErrorEnabled) error(msg.toStringSafe(), t) + } +} diff --git a/src/main/kotlin/mu/KLogging.kt b/kotlin-logging-jvm/src/main/kotlin/mu/KLogging.kt similarity index 100% rename from src/main/kotlin/mu/KLogging.kt rename to kotlin-logging-jvm/src/main/kotlin/mu/KLogging.kt diff --git a/src/main/kotlin/mu/KotlinLogging.kt b/kotlin-logging-jvm/src/main/kotlin/mu/KotlinLogging.kt similarity index 100% rename from src/main/kotlin/mu/KotlinLogging.kt rename to kotlin-logging-jvm/src/main/kotlin/mu/KotlinLogging.kt diff --git a/kotlin-logging-jvm/src/main/kotlin/mu/KotlinLoggingMDC.kt b/kotlin-logging-jvm/src/main/kotlin/mu/KotlinLoggingMDC.kt new file mode 100644 index 00000000..1cbd2b8f --- /dev/null +++ b/kotlin-logging-jvm/src/main/kotlin/mu/KotlinLoggingMDC.kt @@ -0,0 +1,42 @@ +package mu + +import org.slf4j.MDC + +/** + * Use a pair in MDC context. Example: + * `withLoggingContext("userId" to userId) { + * doSomething() + * }` + */ +inline fun withLoggingContext(pair: Pair, body: () -> T): T = + MDC.putCloseable(pair.first, pair.second).use { body() } + +/** + * Use a vary number of pairs in MDC context. Example: + * `withLoggingContext("userId" to userId) { + * doSomething() + * }` + */ +inline fun withLoggingContext(vararg pair: Pair, body: () -> T): T { + try { + pair.forEach { MDC.put(it.first, it.second) } + return body() + } finally { + pair.forEach { MDC.remove(it.first) } + } +} + +/** + * Use a map in MDC context. Example: + * `withLoggingContext(mapOf("userId" to userId)) { + * doSomething() + * }` + */ +inline fun withLoggingContext(map: Map, body: () -> T): T { + try { + map.forEach { MDC.put(it.key, it.value) } + return body() + } finally { + map.forEach { MDC.remove(it.key) } + } +} diff --git a/src/main/kotlin/mu/internal/KLoggerFactory.kt b/kotlin-logging-jvm/src/main/kotlin/mu/internal/KLoggerFactory.kt similarity index 100% rename from src/main/kotlin/mu/internal/KLoggerFactory.kt rename to kotlin-logging-jvm/src/main/kotlin/mu/internal/KLoggerFactory.kt diff --git a/src/main/kotlin/mu/internal/KLoggerNameResolver.kt b/kotlin-logging-jvm/src/main/kotlin/mu/internal/KLoggerNameResolver.kt similarity index 100% rename from src/main/kotlin/mu/internal/KLoggerNameResolver.kt rename to kotlin-logging-jvm/src/main/kotlin/mu/internal/KLoggerNameResolver.kt diff --git a/src/main/kotlin/mu/internal/LocationAwareKLogger.kt b/kotlin-logging-jvm/src/main/kotlin/mu/internal/LocationAwareKLogger.kt similarity index 100% rename from src/main/kotlin/mu/internal/LocationAwareKLogger.kt rename to kotlin-logging-jvm/src/main/kotlin/mu/internal/LocationAwareKLogger.kt diff --git a/src/main/kotlin/mu/internal/LocationIgnorantKLogger.kt b/kotlin-logging-jvm/src/main/kotlin/mu/internal/LocationIgnorantKLogger.kt similarity index 100% rename from src/main/kotlin/mu/internal/LocationIgnorantKLogger.kt rename to kotlin-logging-jvm/src/main/kotlin/mu/internal/LocationIgnorantKLogger.kt diff --git a/src/main/kotlin/mu/internal/MessageInvoker.kt b/kotlin-logging-jvm/src/main/kotlin/mu/internal/MessageInvoker.kt similarity index 100% rename from src/main/kotlin/mu/internal/MessageInvoker.kt rename to kotlin-logging-jvm/src/main/kotlin/mu/internal/MessageInvoker.kt diff --git a/src/test/kotlin/mu/ClassWithLoggingForLocationTesting.kt b/kotlin-logging-jvm/src/test/kotlin/mu/ClassWithLoggingForLocationTesting.kt similarity index 100% rename from src/test/kotlin/mu/ClassWithLoggingForLocationTesting.kt rename to kotlin-logging-jvm/src/test/kotlin/mu/ClassWithLoggingForLocationTesting.kt diff --git a/kotlin-logging-jvm/src/test/kotlin/mu/KotlinLoggingMDCTest.kt b/kotlin-logging-jvm/src/test/kotlin/mu/KotlinLoggingMDCTest.kt new file mode 100644 index 00000000..eb57af49 --- /dev/null +++ b/kotlin-logging-jvm/src/test/kotlin/mu/KotlinLoggingMDCTest.kt @@ -0,0 +1,41 @@ +package mu + +import org.junit.Assert.* +import org.junit.Test +import org.slf4j.MDC + +class KotlinLoggingMDCTest { + + @Test + fun `simple pair withLoggingContext`() { + assertNull(MDC.get("a")) + withLoggingContext("a" to "b") { + assertEquals("b", MDC.get("a")) + } + assertNull(MDC.get("a")) + } + + @Test + fun `multiple pair withLoggingContext`() { + assertNull(MDC.get("a")) + assertNull(MDC.get("c")) + withLoggingContext("a" to "b", "c" to "d") { + assertEquals("b", MDC.get("a")) + assertEquals("d", MDC.get("c")) + } + assertNull(MDC.get("a")) + assertNull(MDC.get("c")) + } + + @Test + fun `map withLoggingContext`() { + assertNull(MDC.get("a")) + assertNull(MDC.get("c")) + withLoggingContext(mapOf("a" to "b", "c" to "d")) { + assertEquals("b", MDC.get("a")) + assertEquals("d", MDC.get("c")) + } + assertNull(MDC.get("a")) + assertNull(MDC.get("c")) + } +} diff --git a/src/test/kotlin/mu/KotlinLoggingTest.kt b/kotlin-logging-jvm/src/test/kotlin/mu/KotlinLoggingTest.kt similarity index 100% rename from src/test/kotlin/mu/KotlinLoggingTest.kt rename to kotlin-logging-jvm/src/test/kotlin/mu/KotlinLoggingTest.kt diff --git a/src/test/kotlin/mu/LoggingTest.kt b/kotlin-logging-jvm/src/test/kotlin/mu/LoggingTest.kt similarity index 100% rename from src/test/kotlin/mu/LoggingTest.kt rename to kotlin-logging-jvm/src/test/kotlin/mu/LoggingTest.kt diff --git a/src/test/kotlin/mu/LoggingWithLocationTest.kt b/kotlin-logging-jvm/src/test/kotlin/mu/LoggingWithLocationTest.kt similarity index 100% rename from src/test/kotlin/mu/LoggingWithLocationTest.kt rename to kotlin-logging-jvm/src/test/kotlin/mu/LoggingWithLocationTest.kt diff --git a/src/test/kotlin/mu/internal/KLoggerNameResolverTest.kt b/kotlin-logging-jvm/src/test/kotlin/mu/internal/KLoggerNameResolverTest.kt similarity index 100% rename from src/test/kotlin/mu/internal/KLoggerNameResolverTest.kt rename to kotlin-logging-jvm/src/test/kotlin/mu/internal/KLoggerNameResolverTest.kt diff --git a/src/test/resources/log4j.properties b/kotlin-logging-jvm/src/test/resources/log4j.properties similarity index 100% rename from src/test/resources/log4j.properties rename to kotlin-logging-jvm/src/test/resources/log4j.properties diff --git a/settings.gradle b/settings.gradle index f79db73f..f8af0e4a 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,2 +1,3 @@ -rootProject.name = 'kotlin-logging' - +include ':kotlin-logging-jvm' +include ':kotlin-logging-js' +include ':kotlin-logging-common' diff --git a/src/main/kotlin/mu/KLogger.kt b/src/main/kotlin/mu/KLogger.kt deleted file mode 100644 index 20b26ce4..00000000 --- a/src/main/kotlin/mu/KLogger.kt +++ /dev/null @@ -1,87 +0,0 @@ -package mu - -import mu.internal.toStringSafe -import org.slf4j.Logger - -/** - * An extension for [Logger] with Lazy message evaluation - * example: - * logger.info{"this is $lazy evaluated string"} - */ -interface KLogger: Logger{ - - /** - * The actual logger executing logging - */ - val underlyingLogger: Logger - - /** - * Lazy add a log message if isTraceEnabled is true - */ - fun trace(msg: () -> Any?) { - if (isTraceEnabled) trace(msg.toStringSafe()) - } - - /** - * Lazy add a log message if isDebugEnabled is true - */ - fun debug(msg: () -> Any?) { - if (isDebugEnabled) debug(msg.toStringSafe()) - } - - /** - * Lazy add a log message if isInfoEnabled is true - */ - fun info(msg: () -> Any?) { - if (isInfoEnabled) info(msg.toStringSafe()) - } - - /** - * Lazy add a log message if isWarnEnabled is true - */ - fun warn(msg: () -> Any?) { - if (isWarnEnabled) warn(msg.toStringSafe()) - } - - /** - * Lazy add a log message if isErrorEnabled is true - */ - fun error(msg: () -> Any?) { - if (isErrorEnabled) error(msg.toStringSafe()) - } - - /** - * Lazy add a log message with throwable payload if isTraceEnabled is true - */ - fun trace(t: Throwable, msg: () -> Any?) { - if (isTraceEnabled) trace(msg.toStringSafe(), t) - } - - /** - * Lazy add a log message with throwable payload if isDebugEnabled is true - */ - fun debug(t: Throwable, msg: () -> Any?) { - if (isDebugEnabled) debug(msg.toStringSafe(), t) - } - - /** - * Lazy add a log message with throwable payload if isInfoEnabled is true - */ - fun info(t: Throwable, msg: () -> Any?) { - if (isInfoEnabled) info(msg.toStringSafe(), t) - } - - /** - * Lazy add a log message with throwable payload if isWarnEnabled is true - */ - fun warn(t: Throwable, msg: () -> Any?) { - if (isWarnEnabled) warn(msg.toStringSafe(), t) - } - - /** - * Lazy add a log message with throwable payload if isErrorEnabled is true - */ - fun error(t: Throwable, msg: () -> Any?) { - if (isErrorEnabled) error(msg.toStringSafe(), t) - } -} diff --git a/versions.gradle b/versions.gradle new file mode 100644 index 00000000..328a91c3 --- /dev/null +++ b/versions.gradle @@ -0,0 +1,2 @@ +ext.kotlin_version='1.2.20' +ext.sl4j_version='1.7.25'