机械手框架:通过log4j的ConsoleAppender发送的日志消息在输出中不可见 [英] Robot Framework: log messages sent through log4j's ConsoleAppender are not visible in output

查看:418
本文介绍了机械手框架:通过log4j的ConsoleAppender发送的日志消息在输出中不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将Robot Framework与在Java库中实现的自定义关键字一起使用.从我的java类直接写入System.out的消息在机械手输出中可见-正如文档中所承诺的那样.但是,由于关键字实现是可重用的组件,独立于机器人框架,因此我希望在那里具有更灵活的日志记录,而不是直接使用System.out.我以为如果将日志输出重定向到System.out(使用log4j的ConsoleAppender),则消息将在机械手输出中可见.不幸的是,它不起作用.

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.

我的log4j属性文件:

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.

您是否知道上述配置有什么问题?或有其他建议使用机械手日志,同时避免直接从我的java类中直接使用System.out?

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?

推荐答案

默认情况下,ConsoleAppender使用保存的对System.out或System.err的引用.要覆盖此行为,有一个跟随属性,您必须将其设置为true. 尝试将其添加到您的log4j.properties文件中:

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

log4j.appender.Stdout.follow=true

这篇关于机械手框架:通过log4j的ConsoleAppender发送的日志消息在输出中不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆