我想在我的自定义 gradle 插件中配置 slf4j-log4j,但无法让它工作。日志输出不会打印到控制台
我的配置是这样的:
我在/src/main/resources下的gradle插件项目中创建了一个“log4j2.xml”
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
</Console>
<File name="Audit" fileName="./logs/audit.log" immediateFlush="false" append="false">
<PatternLayout pattern="%d{yyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</File>
</Appenders>
<Loggers>
<Root level="debug">
<AppenderRef ref="Console" />
<AppenderRef ref="Audit"/>
</Root>
</Loggers>
</Configuration>
build.gradle
dependencies {
implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.17.2'
implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.17.2'
implementation group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.17.2'
}
我现在从插件调用任务
project.tasks.register('log-test') {
Logger logger = LoggerFactory.getLogger(this.class)
logger.info('##### INFO #####')
logger.error('##### ERROR #####')
logger.debug('##### DEBUG #####')
}
我只收到错误和 gradle 标准输出:
> Task :logtest:log-test UP-TO-DATE
BUILD SUCCESSFUL in 144ms
8 actionable tasks: 8 up-to-date
##### ERROR #####
22:50:11: Execution finished 'log-test'.