Robot Framework: log messages sent through log4j's ConsoleAppender are not visible in output

北慕城南 提交于 2019-12-09 23:46:06

问题


I use Robot Framework with custom keywords implemented in java libraries. Messages written directly to System.out from my java classes are visible in the robot output - as promised in documentation. However, since the keyword implementations are reusable components, independent from robot framework, I wanted to have more flexible logging there and not using System.out directly. I thought if I redirect my log output to System.out (with log4j's ConsoleAppender), the messages will be visible in robot output. Unfortunately it does not work.

My log4j properties file:

log4j.appender.Stdout=org.apache.log4j.ConsoleAppender
log4j.appender.Stdout.Target=System.out
log4j.appender.Stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.Stdout.layout.conversionPattern=%d %-5p [%t] %F:%L %m%n
log4j.appender.Stdout.ImmediateFlush=true

log4j.appender.FA=org.apache.log4j.FileAppender
log4j.appender.FA.File=mylog.log
log4j.appender.FA.layout=org.apache.log4j.PatternLayout
log4j.appender.FA.layout.ConversionPattern=%d %-5p [%t] %F:%L %m%n

log4j.rootLogger=INFO,Stdout,FA

The file appender works fine, the log file is created and contains all log messages, but the same messages are not visible either on console or in robot output reports. When I run my components without robot framework, the same config works for console as well.

Do you have an ideas what is wrong with the above configuration? Or any other suggestions to have robot logs while avoiding the direct usage of System.out from my java classes?


回答1:


By default, the ConsoleAppender uses a saved reference to System.out or System.err. To override this behavior, there is a follow property you must set to true. Try adding this to your log4j.properties file:

log4j.appender.Stdout.follow=true



来源:https://stackoverflow.com/questions/19095403/robot-framework-log-messages-sent-through-log4js-consoleappender-are-not-visib

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!