简体   繁体   English

机器人框架信息消息不打印

[英]robot framework info message not printing

My python code generates a log file using logging framework and all INFO messages are captured in the log file. 我的python代码使用日志框架生成日志文件,所有INFO消息都在日志​​文件中捕获。 I integrated my program with ROBOT framework and now the log file is not generated. 我将我的程序与ROBOT框架集成,现在不生成日志文件。 Instead the INFO messages are printed in the log.html . 而是在log.html中打印INFO消息。 I understand this is because robot existing logger is being called and hence INFO are directed to log.html . 我理解这是因为正在调用机器人现有的记录器,因此INFO被定向到log.html I don't want the behavior to change, I still want the user defined log file to be generated separately with just the INFO level messages. 我不希望行为发生变化,我仍然希望仅使用INFO级别消息单独生成用户定义的日志文件。

How can I achieve this? 我怎样才能做到这一点?

The issue has been fixed now, which was a very minor one. 这个问题现在已经解决,这是一个非常小的问题。 But am still analyzing it deeper, will update when I am clear on the exact cause. 但我仍然在深入分析它,当我清楚确切的原因时会更新。 This was the module that I used, 这是我用的模块,

def call_logger(logger_name, logFile):
        level = logging.INFO
        l = logging.getLogger(logger_name)
        if not getattr(l, 'handler_set', None):
                formatter = logging.Formatter('%(asctime)s : %(message)s')
                fileHandler = logging.FileHandler(logFile, mode = 'a')
                fileHandler.setFormatter(formatter)
                streamHandler = logging.StreamHandler()
                streamHandler.setFormatter(formatter)
                l.setLevel(level)
                l.addHandler(fileHandler)
                l.addHandler(streamHandler)
                l.handler_set = True

When I changed the parameter "logFile" to a different name "log_file" it worked. 当我将参数“logFile”更改为其他名称“log_file”时,它工作正常。 Looks like "logFile" was a built in robot keyword. 看起来“logFile”是一个内置的机器人关键字。

Python Code --> Logging Library --> "Log File" Python代码 - >日志库 - >“日志文件”

RobotFramework --> Python Code --> Logging Library --> by default "log.html" RobotFramework - > Python代码 - >日志库 - >默认情况下为“log.html”

When you run using python code it will allow you set log file name. 当您使用python代码运行时,它将允许您设置日志文件名。 But when you run using robotframework, the file is by default set to log.html (since robot uses the same logging library internally that you are using) so your logging function is overridden by that of robotframework. 但是当你使用robotframework运行时,默认情况下该文件设置为log.html(因为机器人在内部使用相同的日志库),因此你的日志记录功能会被机器人框架覆盖。

That is why you see it in log.html instead of your file. 这就是为什么你在log.html而不是你的文件中看到它。

You can also refer Robot Framework not creating file or writing to it 您也可以参考Robot Framework而不是创建文件或写入文件

Hope it helps! 希望能帮助到你!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM