当前位置:网站首页>Logging log configuration of vertx
Logging log configuration of vertx
2022-07-03 07:25:00 【Sleeping Empire】
Introduce
Vertx Support the use of its internal customized logging method , It also supports user-defined logging
- Configuration through environment variables vertx.logger-delegate-factory-class-name
- If classpath There are vertx-default-jul-logging.properties file , The default is jdk journal
- stay classpath Use if there are the following dependencies , The order is as follows :
- SLF4J
- Log4J
- Log4J2
1. maven Project dependence
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-web</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>com.lmax</groupId>
<artifactId>disruptor</artifactId>
<version>3.4.4</version>
</dependency>
2.log4j2.xml The configuration is as follows
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Properties>
<property name="CONSOLE_LOG_PATTERN"
value="%d{yyyy-MM-dd HH:mm:ss.SSS} %highlight{%5p}{TRACE=blue, DEBUG=green, INFO=green,
WARN=yellow, ERROR=red, FATAL=red} %tid --- [%style{%15.15t}{magenta}] %-40.40logger{39}---[%4L] : %m%n"/>
<property name="FILE_LOG_PATTERN"
value="%d{yyyy-MM-dd HH:mm:ss.SSS} %5p %tid --- [%15.15t] %-40.40logger{39}---[%4L] : %m%n"/>
</Properties>
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="${CONSOLE_LOG_PATTERN}"/>
</Console>
<RollingRandomAccessFile name="FILE" fileName="logs/logging-log4j2.log" append="true"
filePattern="logs/logging-log4j2.log.%d{yyyyMMdd}">
<PatternLayout>
<Pattern>${FILE_LOG_PATTERN}</Pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="24" modulate="true"/>
</Policies>
</RollingRandomAccessFile>
</Appenders>
<Loggers>
<AsyncLogger name="com.lance.logging" level="debug" additivity="false" includeLocation="true">
<AppenderRef ref="Console"/>
<appender-ref ref="FILE"/>
</AsyncLogger>
<Root level="debug">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>
3. The log is printed as follows
@Slf4j
public class MainVerticle extends AbstractVerticle {
@Override
public void start(Promise<Void> startPromise) throws Exception {
vertx.createHttpServer().requestHandler(req -> {
IntStream.range(0, 100).forEach(i -> log.info("===>start print i: {}, time: {}", i, System.nanoTime()));
req.response().putHeader("content-type", "text/plain").end("Hello from Vert.x!");
}
).listen(8888, http -> {
if (http.succeeded()) {
startPromise.complete();
log.info("HTTP server started on port 8888");
} else {
startPromise.fail(http.cause());
}
});
}
}
4. Full address of the project
边栏推荐
猜你喜欢
随机推荐
VMware network mode - bridge, host only, NAT network
Dora (discover offer request recognition) process of obtaining IP address
IP home online query platform
你开发数据API最快多长时间?我1分钟就足够了
树莓派更新工具链
C WinForm framework
[cmake] cmake link SQLite Library
Flask Foundation
【已解决】win10找不到本地组策略编辑器解决方法
论文学习——鄱阳湖星子站水位时间序列相似度研究
IPv4 address
Common problems in io streams
I. D3.js hello world
FileInputStream and fileoutputstream
Recursion, Fibonacci sequence
Take you through the whole process and comprehensively understand the software accidents that belong to testing
2. E-commerce tool cefsharp autojs MySQL Alibaba cloud react C RPA automated script, open source log
Use of generics
20220319
Store WordPress media content on 4everland to complete decentralized storage