我尝试编写一个http服务器,我想按照建议进行注销。但是,我写的Verticle似乎不受我使用的logback.xml控制。
然后我写了我能想到的最简单的Verticle,但似乎我的logback.xml完全不起作用。
这是我的垂直示例:
import io.vertx.core.AbstractVerticle;
import io.vertx.core.Future;
import io.vertx.core.logging.Logger;
import io.vertx.core.logging.LoggerFactory;
import io.vertx.core.logging.SLF4JLogDelegateFactory;
public class SimplestVerticle extends AbstractVerticle {
private static final Logger LOGGER = LoggerFactory.getLogger(SimplestVerticle.class);
@Override
public void start(Future<Void> future) {
Future<Void> newFuture = Future.future();
LOGGER.debug("This is debug");
LOGGER.info("This is info");
LOGGER.error("This is error");
newFuture.setHandler(future);
}
}
这是我的pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>[xxx]</groupId>
<artifactId>[xxx]</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
<version>3.7.0</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>io.vertx.core.Starter</Main-Class>
<Main-Verticle>
[somepackage.]SimplestVerticle
</Main-Verticle>
</manifestEntries>
</transformer>
</transformers>
<artifactSet/>
<outputFile>${project.build.directory}/${project.artifactId}-${project.version}-fat.jar</outputFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
这是我的logback.xml,放在src / main / resources /下
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="error">
<appender-ref ref="STDOUT"/>
</root>
</configuration>
但是,当我运行“mvn package”生成的fat jar时,输出为:
Apr 18, 2019 7:03:31 AM [package.name].SimplestVerticle
INFO: This is info
Apr 18, 2019 7:03:31 AM [package.name].SimplestVerticle
SEVERE: This is error
此处仍显示INFO级别的日志。
在3.x及更低版本中,必须使用系统属性指定日志记录后端:
-Dvertx.logger-delegate-factory-class-name=io.vertx.core.logging.Log4jLogDelegateFactory
从4.0版开始(尚未发布),Vert.x将解析日志记录后端,如下所示:
vertx.logger-delegate-factory-class-name
sysprop的值,如果存在,或vertx-default-jul-logging.properties
文件,则jdk记录:如果以上都不起作用,它将回退到jdk日志记录。
此行为与Netty的日志记录后端解析过程一致。