在我的Storm APP中,每次我跑步时,我都会从控制台获取这些线路:
2018-01-17 18:38:30,417 main DEBUG Initializing configuration XmlConfiguration[location=D:\Desarrollo\workspaces\oxygen_main\StormAcustat\target\classes\log4j2.xml]
2018-01-17 18:38:30,426 main DEBUG Installed script engines
2018-01-17 18:38:31,172 main DEBUG Oracle Nashorn Version: 1.8.0_144, Language: ECMAScript, Threading: Not Thread Safe, Compile: true, Names: {nashorn, Nashorn, js, JS, JavaScript, javascript, ECMAScript, ecmascript}
2018-01-17 18:38:31,172 main DEBUG PluginManager 'Core' found 112 plugins
2018-01-17 18:38:31,173 main DEBUG PluginManager 'Level' found 0 plugins
2018-01-17 18:38:31,185 main DEBUG PluginManager 'Lookup' found 13 plugins
2018-01-17 18:38:31,189 main DEBUG Building Plugin[name=layout, class=org.apache.logging.log4j.core.layout.PatternLayout].
2018-01-17 18:38:31,214 main DEBUG PluginManager 'TypeConverter' found 26 plugins
2018-01-17 18:38:31,255 main DEBUG PatternLayout$Builder(pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n", PatternSelector=null, Configuration(D:\Desarrollo\workspaces\oxygen_main\StormAcustat\target\classes\log4j2.xml), Replace=null, charset="null", alwaysWriteExceptions="null", disableAnsi="null", noConsoleNoAnsi="null", header="null", footer="null")
2018-01-17 18:38:31,255 main DEBUG PluginManager 'Converter' found 41 plugins
2018-01-17 18:38:31,259 main DEBUG Building Plugin[name=appender, class=org.apache.logging.log4j.core.appender.ConsoleAppender].
2018-01-17 18:38:31,282 main DEBUG ConsoleAppender$Builder(target="SYSTEM_OUT", follow="null", direct="null", bufferedIo="null", bufferSize="null", immediateFlush="null", ignoreExceptions="null", PatternLayout(%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n), name="Console", Configuration(D:\Desarrollo\workspaces\oxygen_main\StormAcustat\target\classes\log4j2.xml), Filter=null)
2018-01-17 18:38:31,283 main DEBUG Jansi is not installed, cannot find org.fusesource.jansi.WindowsAnsiOutputStream
2018-01-17 18:38:31,284 main DEBUG Starting OutputStreamManager SYSTEM_OUT.false.false
我已配置log4j2.xml
以使Storm将其日志重定向到不同的日志文件中,并且它正在运行:
<Loggers>
<Logger name="org.apache.storm" level="debug" additivity="false">
<AppenderRef ref="Storm"/>
</Logger>
<Logger name="org.apache.storm.kafka" level="debug" additivity="false">
<AppenderRef ref="Storm-Kafka"/>
</Logger>
<Logger name="org.apache.zookeeper" level="debug" additivity="false">
<AppenderRef ref="ZooKeeper"/>
</Logger>
<Logger name="org.apache.storm.shade.org.apache.zookeeper" level="debug" additivity="false">
<AppenderRef ref="Storm-ZooKeeper"/>
</Logger>
<Logger name="TestMain" level="info">
<AppenderRef ref="TestMain"/>
</Logger>
<!-- these lines don't work -->
<Logger name="org.apache.logging.log4j" level="info">
<AppenderRef ref="Storm-logging"/>
</Logger>
<Root level="OFF">
<AppenderRef ref="Console" />
</Root>
</Loggers>
但我仍然从控制台获取这些日志。我希望使用log4j
或log4j2
配置消除它。
我检查了日志,发现这些日志似乎来自org.apache.logging.log4j
本身,而不是来自任何其他Storm类,因为org.apache.storm
,org.apache.storm.kafka
等日志文件在,不包括这些行,并检查源代码,在类中可以看到PluginManager {} found {} plugins
:
org.apache.logging.log4j.core.config.plugins.util.PluginManager.class
它位于其中一个依赖项log4j-core-2.8.2.jar
。
所以,似乎控制台打印的是来自log4j
的日志,而不是来自Storm。
如何预防?正如你所看到的,我已经关闭了root logger并且我有这些行,但它们不起作用:
<Logger name="org.apache.logging.log4j" level="info">
<AppenderRef ref="Storm-logging"/>
</Logger>
编辑:我的log4j2.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="DEBUG">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
</Console>
<RollingFile name="TestMain" fileName="D:\Proyectos\Storm\test\TestMain.log" filePattern="D:\Proyectos\Storm\test\TestMain.%d{yyyy-MM-dd}.log"
bufferedIO="true" immediateFlush="true" append="true" ignoreExceptions="false"> <!-- bufferedIO: large performance improvement -->
<PatternLayout pattern="%d{yyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
</Policies>
</RollingFile>
<RollingFile name="Storm" fileName="D:\Proyectos\Storm\test\Storm.log" filePattern="D:\Proyectos\Storm\test\Storm.%d{yyyy-MM-dd}.log"
bufferedIO="true" immediateFlush="true" append="true" ignoreExceptions="false"> <!-- bufferedIO: large performance improvement -->
<PatternLayout pattern="%d{yyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
</Policies>
</RollingFile>
<RollingFile name="Storm-Kafka" fileName="D:\Proyectos\Storm\test\Storm-Kafka.log" filePattern="D:\Proyectos\Storm\test\Storm-Kafka.%d{yyyy-MM-dd}.log"
bufferedIO="true" immediateFlush="true" append="true" ignoreExceptions="false"> <!-- bufferedIO: large performance improvement -->
<PatternLayout pattern="%d{yyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
</Policies>
</RollingFile>
<RollingFile name="ZooKeeper" fileName="D:\Proyectos\Storm\test\ZooKeeper.log" filePattern="D:\Proyectos\Storm\test\ZooKeeper.%d{yyyy-MM-dd}.log"
bufferedIO="true" immediateFlush="true" append="true" ignoreExceptions="false"> <!-- bufferedIO: large performance improvement -->
<PatternLayout pattern="%d{yyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
</Policies>
</RollingFile>
<RollingFile name="Storm-ZooKeeper" fileName="D:\Proyectos\Storm\test\Storm-ZooKeeper.log" filePattern="D:\Proyectos\Storm\test\Storm-ZooKeeper.%d{yyyy-MM-dd}.log"
bufferedIO="true" immediateFlush="true" append="true" ignoreExceptions="false"> <!-- bufferedIO: large performance improvement -->
<PatternLayout pattern="%d{yyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
</Policies>
</RollingFile>
<RollingFile name="Storm-logging" fileName="D:\Proyectos\Storm\test\Storm-logging.log" filePattern="D:\Proyectos\Storm\test\Storm-logging.%d{yyyy-MM-dd}.log"
bufferedIO="true" immediateFlush="true" append="true" ignoreExceptions="false"> <!-- bufferedIO: large performance improvement -->
<PatternLayout pattern="%d{yyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
</Policies>
</RollingFile>
</Appenders>
<Loggers>
<Logger name="org.apache.storm" level="debug" additivity="false">
<AppenderRef ref="Storm"/>
</Logger>
<Logger name="org.apache.storm.kafka" level="debug" additivity="false">
<AppenderRef ref="Storm-Kafka"/>
</Logger>
<Logger name="org.apache.zookeeper" level="debug" additivity="false">
<AppenderRef ref="ZooKeeper"/>
</Logger>
<Logger name="org.apache.storm.shade.org.apache.zookeeper" level="debug" additivity="false">
<AppenderRef ref="Storm-ZooKeeper"/>
</Logger>
<Logger name="TestMain" level="info">
<AppenderRef ref="TestMain"/>
</Logger>
<Logger name="org.apache.logging.log4j" level="info">
<AppenderRef ref="Storm-logging"/>
</Logger>
<Root level="OFF">
<AppenderRef ref="Console" />
</Root>
</Loggers>
</Configuration>
答案 0 :(得分:1)
要打印的日志属于log4j2
,因为您已启用debug
级log4j2
级日志记录。
要关闭此详细日志记录,请将配置中status
元素的Configuration
属性更改为warn
或error
-
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn">
<Appenders>
...
休息应保持不变。
Log4j2 documentation详细介绍了此日志记录 -
从log4j-2.9开始
从log4j-2.9开始,log4j2将打印所有内部日志记录到 控制台,如果定义了系统属性
log4j2.debug
(任何或没有 值)。在log4j-2.9之前
在log4j-2.9之前,有两个地方可以进行内部日志记录 控制:
如果找到配置文件正确,则log4j2内部状态 可以通过设置
<Configuration status="trace">
来控制日志记录 配置文件。这将显示详细的log4j2内部日志 控制台上有关配置期间发生的情况的语句 处理。这可能有助于解决配置问题。通过 默认情况下,状态记录器级别为WARN,因此您只能看到通知 当出现问题时。如果找不到配置文件,您仍然可以启用 通过设置系统属性来记录log4j2内部状态
-Dorg.apache.logging.log4j.simplelog.StatusLogger.level=TRACE
。