How can I disable console logging completely in production? (eg using spring.profiles.active=production
?
During dev I always want to see the full console logging. But in production I'd like to prevent console out. But how?
log4j2-spring.xml:
<configuration>
<Appenders>
<Console name="CONSOLE" target="SYSTEM_OUT">
<ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY" />
</Console>
<RollingRandomAccessFile name="XML" .../>
</Appenders>
<Loggers>
<Root level="all">
<AppenderRef ref="CONSOLE" />
<AppenderRef ref="XML" />
</Root>
</Loggers>
</configuration>
Sidenote: the INFO statements should still be logged to XML file. They should just not be printed to console additionally.
It's possible using vm args as follows:
<Configuration>
<Properties>
<property name="console.log">INFO</property> <!-- default value if not set -->
</Properties>
<Console name="CONSOLE" target="SYSTEM_OUT">
<ThresholdFilter level="${sys:console.log}" onMatch="ACCEPT" onMismatch="DENY" />
</Console>
The logger will use INFO
level by default. And when providing eg -Dconsole.log=ERROR
on launch, it will only log errors to console.
Would be even nicer if log4j2 could read just a property defined in application-production.properties
, but for not the approach works.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.