通过robot框架运行python日志时出现日志更新问题
问题:通过robot文件调用以下日志方法时,无法在控制台中打印所有日志类型,在日志文件中没有通过robot框架运行python日志时出现日志更新问题,python,robotframework,Python,Robotframework,问题:通过robot文件调用以下日志方法时,无法在控制台中打印所有日志类型,在日志文件中没有 import logging from colorlog import ColoredFormatter class Log(): LOG_LEVEL = logging.DEBUG LOGFORMAT = " %(log_color)s%(levelname)-8s%(reset)s | %(log_color)s%(message)s%(reset)s" logging.
import logging
from colorlog import ColoredFormatter
class Log():
LOG_LEVEL = logging.DEBUG
LOGFORMAT = " %(log_color)s%(levelname)-8s%(reset)s | %(log_color)s%(message)s%(reset)s"
logging.root.setLevel(LOG_LEVEL)
formatter = ColoredFormatter(LOGFORMAT)
stream = logging.StreamHandler()
stream.setLevel(LOG_LEVEL)
stream.setFormatter(formatter)
Log = logging.getLogger('pythonConfig')
Log.setLevel(LOG_LEVEL)
Log.addHandler(stream)
logger = logging.getLogger(__name__)
logging.basicConfig(
filename='c://foo//app.log',
format='%(asctime)s - %(levelname)s: %(message)s',
datefmt='%d-%b-%y %H:%M:%S', level=logging.INFO,
)
@classmethod
def warn(cls, message):
cls.Log.warning(message)
@classmethod
def info(cls, message):
cls.Log.info(message)
@classmethod
def error(cls, message):
cls.Log.error(message)
@classmethod
def debug(cls, message):
cls.Log.debug(message)
# Calling class methods
Log.warn("test")
Log.info("test")
Log.error("test")
Log.debug("test")
从命令提示符下使用python运行:-
C:foo>py log.py
WARNING | test
INFO | test
ERROR | test
DEBUG | test
*** Settings ***
Library ../Robot/Log.py
*** Test Cases ***
testinglogger
info test
error test
debug test
warn test
应用程序日志
01-Sep-19 21:32:31 - WARNING: test
01-Sep-19 21:32:31 - INFO: test
01-Sep-19 21:32:31 - ERROR: test
01-Sep-19 21:32:31 - DEBUG: test
当我通过robot文件(Python>>robot suite)调用相同的方法时,我无法在日志文件(app.log)中打印任何日志,只能看到控制台中打印的错误和警告消息。有人能帮我这方面的忙吗
Runner.py
import robot
logFile = open('c:\\foo\\ExecutionReport.txt','w')
htmlpath = "c:\\foo\\Reports.html"
robot.run("c:\\foo\\test_sample.robot", log=None,report=htmlpath, output=None,
stdout=logFile)
机器人:-
C:foo>py log.py
WARNING | test
INFO | test
ERROR | test
DEBUG | test
*** Settings ***
Library ../Robot/Log.py
*** Test Cases ***
testinglogger
info test
error test
debug test
warn test
应用程序日志:
没有
在Python
Runner.py
脚本中,您正在调用robot.run
函数并设置一些执行参数,例如log=None
和output=None
。这导致不创建任何日志文件(无输出),也不显示任何日志记录(在ERROR
和WARN
之外)
请参见以下机器人框架运行参数:
-o——输出文件
,其中file是机器人输出的名称。将NONE
设置为该值也会导致禁用报告和所有其他文件日志记录
保留未分配以创建Robot框架的默认日志文件。我相信这会映射到robot.run命令的输出
参数
-L——日志级别
其中级别是所需的最低日志级别
可用级别:跟踪
,调试
,信息
(默认),警告
,无
(无日志记录)。在这种情况下,您可能希望将其设置为DEBUG
对Runner.py
脚本进行必要的更改,然后重试:)
以下是最新版本3.1.2
Robot框架的Robot的完整文档。运行脚本:
有人能在这方面帮助我吗?有什么帮助吗?我已经按照你的建议进行了编辑,但仍然没有更新日志文件robot.run(“C:\\foo\\test\u sample.robot”,log=log,report=report,output=output,loglevel=logging.DEBUG,stdout=exec\u report)还有什么帮助吗?