sre*_*ari 8 groovy logback spring-boot logback-groovy
我在Spring-boot应用程序中混合使用Groovy和Java.Rest控制器和数据访问是用Groovy编写的.配置主要是Java.
根据logback文档,如果类路径中有logback.groovy文件,则应该在logback.xml之前选择它.但是只有logback.xml在我的情况下工作.
我正在运行应用程序作为sprint-boot-application.
此外,值得注意的是,spring建议继承一些日志配置,如下所示
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<logger name="org.springframework.web" level="DEBUG"/>
</configuration>
Run Code Online (Sandbox Code Playgroud)
在Groovy配置中无法执行此操作.
的build.gradle:
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework:spring-jdbc")
compile("com.h2database:h2")
compile("org.hsqldb:hsqldb")
testCompile("junit:junit")
compile('org.codehaus.groovy:groovy-all:2.3.10')
testCompile('org.codehaus.groovy.modules.http-builder:http-builder:0.5.0-RC2')
compile('org.slf4j:slf4j-simple:1.6.1')
}
sourceSets {
main {
groovy {
srcDirs = ['src/main/groovy', 'src/main/java']
}
java {
srcDirs = []
}
}
test {
groovy {
srcDirs = ['src/test/groovy', 'src/test/java']
}
java {
srcDirs = []
}
}
}
Run Code Online (Sandbox Code Playgroud)
首先,你build.gradle对我来说看起来很奇怪:
spring-boot-gradle-pluginsourceSets选项中定义 Groovy 插件的默认值设置,请参阅项目布局dependencies部分中,您使用简单的依赖项而不是Spring Boot 启动器(另请参阅参考文档)尝试使用Spring Initializr创建示例项目- 切换到完整版本。你的build.gradle看起来像
buildscript {
ext {
springBootVersion = '1.5.1.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'groovy'
apply plugin: 'org.springframework.boot'
jar {
baseName = 'demo'
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile 'org.springframework.boot:spring-boot-starter'
compile 'org.springframework.boot:spring-boot-starter-logging'
compile 'org.springframework.boot:spring-boot-starter-jdbc'
compile 'org.codehaus.groovy:groovy'
compile 'com.h2database:h2'
testCompile 'org.springframework.boot:spring-boot-starter-test'
testCompile 'org.codehaus.groovy.modules.http-builder:http-builder:0.5.0-RC2'
}
Run Code Online (Sandbox Code Playgroud)
使用此配置logback.groovy应该可以工作。对于具体问题,只需发布您的logback.groovy. 但正如您所指出的,Groovy 配置并不是一个完整的公民。当您包含启动器时,您还可以使用或spring-boot-starter-logging扩展标准日志记录配置。logback-spring.groovylogback-spring.xml
为了完全控制,您必须使用 XML 配置,对于小型项目,我停止使用logback.groovy,而是通过 中的一些设置来配置日志记录启动器application.properties,请参阅自定义日志配置。
application.properties例如,带有彩色列的日志的一些设置(除 windows < 10 之外的所有平台,在 IDEA 中甚至在 windows < 10 下):
logging.file = logs/jira.log
spring.output.ansi.enabled = DETECT
logging.level.root = INFO
logging.level.org.apache.http = WARN
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1972 次 |
| 最近记录: |