Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
弹簧靴&x2B;Groovy+;logback.groovy_Groovy_Spring Boot_Logback_Logback Groovy - Fatal编程技术网

弹簧靴&x2B;Groovy+;logback.groovy

弹簧靴&x2B;Groovy+;logback.groovy,groovy,spring-boot,logback,logback-groovy,Groovy,Spring Boot,Logback,Logback Groovy,我在我的Spring boot应用程序中混合了Groovy和Java。Rest控制器和数据访问是用Groovy编写的。配置主要使用Java 根据logback文档,如果类路径中有logback.groovy文件,那么应该在logback.xml之前选择它。然而,在我的案例中,只有logback.xml起作用 我正在以sprint启动应用程序的形式运行该应用程序 另外,值得注意的是,spring建议继承一些日志配置,如下所示 <configuration> <includ

我在我的Spring boot应用程序中混合了Groovy和Java。Rest控制器和数据访问是用Groovy编写的。配置主要使用Java

根据logback文档,如果类路径中有logback.groovy文件,那么应该在logback.xml之前选择它。然而,在我的案例中,只有logback.xml起作用

我正在以sprint启动应用程序的形式运行该应用程序

另外,值得注意的是,spring建议继承一些日志配置,如下所示

<configuration>
    <include resource="org/springframework/boot/logging/logback/base.xml"/>
    <logger name="org.springframework.web" level="DEBUG"/>
</configuration>

首先,我觉得你的
build.gradle
很奇怪:

  • 您不包括
    spring boot gradle插件
  • sourceset
    选项中,您可以定义作为Groovy插件默认值的设置,请参阅
  • 注意:即使您混合使用java和groovy文件,您也不必将它们分开(如果您愿意,您可以这样做)。我通常将它们都保存在groovy目录中
  • 依赖项
    部分中,您使用的是简单依赖项而不是(另请参见)
  • 您有2个DB依赖项(H2和HSQL)
尝试使用-切换到完整版本创建示例项目。您的
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'
}
使用此配置
logback.groovy
应该可以工作。对于特定的问题,只需发布您的
logback.groovy
。但是正如您所注意到的,Groovy配置不是一个完整的公民。当您包括
spring启动程序日志记录时
starter,您还可以使用
logback spring.groovy
logback spring.xml
扩展标准日志记录配置

对于完全控制,您必须使用XML配置,对于小项目,我停止使用
logback.groovy
,而只是通过
application.properties
中的一些设置配置日志启动器,请参阅

例如,
application.properties
的一些设置,带有彩色列的日志(除了windows<10和IDEA中的windows<10以外的所有平台):

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'
}
logging.file = logs/jira.log
spring.output.ansi.enabled = DETECT
logging.level.root = INFO
logging.level.org.apache.http = WARN