我正在将kotlin与gradle一起使用,它工作得很好,除了我无法为SimpleLogger
配置日志级别
我有一行src/main/resources/simplelogger.properties
,内容如下:
org.slf4j.simpleLogger.defaultLogLevel=debug
这是我的build.gradle
buildscript {
ext.kotlin_version = '1.3.10'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'kotlin'
apply plugin: 'application'
mainClassName = 'com.snc.token_model.HelloWorldKt'
defaultTasks 'run'
repositories {
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
// https://mvnrepository.com/artifact/org.slf4j/slf4j-simple
compile 'io.github.microutils:kotlin-logging:1.7.6'
compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.6.1'
testCompile 'junit:junit:4.11'
testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
}
jar {
manifest { attributes 'Main-Class': 'demo.HelloWorldKt' }
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
}
task wrapper(type: Wrapper) {
gradleVersion = "4.10.2"
}
这是我的主要功能
package com.snc.token_model
import mu.KotlinLogging
fun getGreeting(): String {
val words = mutableListOf<String>()
words.add("Hello,")
words.add("world!")
return words.joinToString(separator = " ")
}
private val logger = KotlinLogging.logger {}
fun main(args: Array<String>) {
logger.debug { "********** debug log **********" }
logger.info { "********** log **********" }
println(getGreeting())
}
运行./gradlew
时,我得到以下输出
> Task :run
3 [main] INFO com.snc.token_model.HelloWorld - ********** log **********
Hello, world!
应该在********** debug log **********
后面加一行