我的gradle项目使用该application
插件来构建一个jar文件.作为运行时传递依赖的一部分,我最终会进入org.slf4j:slf4j-log4j12
.(它被引用为至少5或6个其他传递依赖的子传递依赖 - 这个项目使用spring和hadoop,所以除了厨房水槽之外的所有东西都被拉进来......没等了......那也是:) ).
我想slf4j-log4j12
从我的内置jar中全局排除jar.所以我试过这个:
configurations {
runtime.exclude group: "org.slf4j", name: "slf4j-log4j12"
}
Run Code Online (Sandbox Code Playgroud)
但是,这似乎排除了所有 org.slf4j
工件,包括slf4j-api
.在调试模式下运行时,我看到以下行:
org.slf4j#slf4j-api is excluded from com.pivotal.gfxd:gfxd-demo-mapreduce:1.0(runtime).
org.slf4j#slf4j-simple is excluded from com.pivotal.gfxd:gfxd-demo-mapreduce:1.0(runtime).
org.slf4j#slf4j-log4j12 is excluded from org.apache.hadoop:hadoop-common:2.2.0(runtime).
Run Code Online (Sandbox Code Playgroud)
我不想查找每个slf4j-log4j12
传递依赖的源,然后compile foo { exclude slf4j... }
在我的dependencies
块中有单独的语句.
更新:
我也试过这个:
configurations {
runtime.exclude name: "slf4j-log4j12"
}
Run Code Online (Sandbox Code Playgroud)
最终排除了构建中的所有内容!好像我指定的那样group: "*"
.
更新2:
我正在使用Gradle版本1.10.
我正在尝试让log4j在我正在进行的项目中工作.我在build.gradle中添加了相关的log4j依赖项,并排除了Spring启动启动日志记录,以便它可以工作.
当我使用Maven作为构建工具时,这工作正常,但是一旦我切换到Gradle,它根本不工作(除了从Spring启动器启动记录).以下是build.gradle中的依赖项
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-web'){
exclude module: 'org.springframework.boot:spring-boot-starter-logging'
}
compile('org.springframework.boot:spring-boot-starter-log4j')
compile('org.springframework.boot:spring-boot-starter-data-rest')
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.postgresql:postgresql:9.3-1101-jdbc41')
compile('org.scala-lang:scala-library:2.10.4')
testCompile('org.springframework.boot:spring-boot-starter-test') {
exclude module: 'commons-logging'
}
providedCompile('org.springframework.boot:spring-boot-starter-tomcat')
}
Run Code Online (Sandbox Code Playgroud)
但是你可以在依赖树中清楚地看到spring-boot-starter-logging
它仍然存在.我猜这就是为什么日志记录不起作用的问题.
这是依赖树:
+--- org.springframework.boot:spring-boot-starter-data-jpa: -> 1.2.1.RELEASE
| +--- org.springframework.boot:spring-boot-starter:1.2.1.RELEASE
| | +--- org.springframework.boot:spring-boot:1.2.1.RELEASE
| | | +--- org.springframework:spring-core:4.1.4.RELEASE
| | | \--- org.springframework:spring-context:4.1.4.RELEASE
| | | +--- org.springframework:spring-aop:4.1.4.RELEASE
| | | | +--- aopalliance:aopalliance:1.0
| | | | +--- org.springframework:spring-beans:4.1.4.RELEASE
| | | | | \--- org.springframework:spring-core:4.1.4.RELEASE
| | | | \--- org.springframework:spring-core:4.1.4.RELEASE
| | …
Run Code Online (Sandbox Code Playgroud) 我是Spring Boot的新手,使用Spring Boot进行简单的log4j演示.我使用了gradle项目并拥有spring-boot-starter-web和groovy依赖项.下面是我的log4j.properties文件内容.我需要的是,当我执行主程序并使用注释@ Log4J时,我必须能够将log.perflog保存到本地(windows)中的文件中.
log4j.rootLogger = WARN , stdout, cslLog
log4j.logger.perfLog = WARN, perfLog
log4j.additivity.perfLog = false
log4j.appender.perfLog = org.apache.log4j.RollingFileAppender
log4j.appender.perfLog.File = ${GRAILS_HOME}/logs/csl.log
log4j.appender.perfLog.Append = true
log4j.appender.perfLog.ImmediateFlush = true
log4j.appender.perfLog.MaxFileSize=200MB
log4j.appender.perfLog.MaxBackupIndex = 1
Run Code Online (Sandbox Code Playgroud)
我的样本groovy类:
package sample.actuator.log4j
import groovy.util.logging.Log4j;
import org.apache.log4j.Logger;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Log4j
@RestController
@EnableAutoConfiguration
class HelloGroovy {
static Logger perfLog = Logger.getLogger("perfLog")
@RequestMapping("/logger")
String logger() {
log.info "created a new item named identifier"
log.error "created a new item named identifier"
log.warn "created a …
Run Code Online (Sandbox Code Playgroud)