简体   繁体   中英

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. I integrated my program with ROBOT framework and now the log file is not generated. Instead the INFO messages are printed in the log.html . I understand this is because robot existing logger is being called and hence INFO are directed to 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.

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. Looks like "logFile" was a built in robot keyword.

Python Code --> Logging Library --> "Log File"

RobotFramework --> Python Code --> Logging Library --> by default "log.html"

When you run using python code it will allow you set log file name. 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.

That is why you see it in log.html instead of your file.

You can also refer Robot Framework not creating file or writing to it

Hope it helps!

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.

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