我不希望将日志打印到控制台,而只打印到文件。 我当前的Log4j2.xml配置不支持此功能,除非我配置了“ level =“ OFF”',但是它不同时写入文件和控制台。 如何配置记录器仅写入文件?
已经尝试注释掉该标记,并注释掉“记录器”标记内的“ appenderRef”标记
log4j2.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<Configuration>
<Appenders>
<RollingFile name="vertx_file" append="true"
fileName="/var/log/vertx.log"
filePattern="/var/log/vertx/$${date:yyyy-MM}/vertx-%d{MM-dd-yyyy}-%i.log.gz">
<PatternLayout pattern="%d{ISO8601} %-5p %c:%L - %m%n" />
<Policies>
<OnStartupTriggeringPolicy />
<SizeBasedTriggeringPolicy size="5MB" />
<TimeBasedTriggeringPolicy />
</Policies>
</RollingFile>
<Console name="STDOUT" target="SYSTEM_OUT">
<!-- <LogStashJSONLayout/> -->
<PatternLayout pattern="%d{ISO8601} %-5p %c:%L - %m%n" />
</Console>
</Appenders>
<Loggers>
<Logger name="com.service.vertex" level="OFF" >
<!-- <AppenderRef ref="vertx_rollingFile" /> -->
<!-- <AppenderRef ref="vertx_socket" /> -->
<!-- <AppenderRef ref="STDOUT" /> -->
<AppenderRef ref="vertx_file" />
</Logger>
<Logger name="org.mongodb.driver" level="OFF">
<AppenderRef ref="vertx_rollingFile" />
<AppenderRef ref="vertx_socket" />
<AppenderRef ref="STDOUT" />
<AppenderRef ref="vertx_file" />
</Logger>
<Root level="INFO">
<AppenderRef ref="vertx_socket" />
<!--<AppenderRef ref="STDOUT" />-->
<AppenderRef ref="vertx_file" />
</Root>
</Loggers>
</Configuration>
日志:
Apr 03, 2019 2:02:35 PM com.service.vertex.dao.UsersCollection
INFO: {"response_code":551,"description":"INVALIDATE SESSION ERROR: null","log_origin":"system","id":"ERROR (57) 14:02:35:050","time":"2019-04-03 14:02:35:050","host_name":"pc","server_port":"444","level":"ERROR","verticle":"admin","remote_address":"172.15.333.21"}
仍在打印到控制台
答案 0 :(得分:0)
在配置中注释以下内容,然后尝试
onStop()
和附加器
activity