【发布时间】:2019-09-03 13:54:40
【问题描述】:
问题:通过机器人文件调用以下日志方法时,无法在控制台中打印所有日志类型,在日志文件中也没有。
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
app.log
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
当我通过机器人文件(Python >> 机器人套件)调用相同的方法时,我无法在日志文件(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)
机器人:-
*** Settings ***
Library ../Robot/Log.py
*** Test Cases ***
testinglogger
info test
error test
debug test
warn test
app.log: 无
【问题讨论】:
-
有人可以帮我解决这个问题吗?
-
有什么帮助吗?
标签: python robotframework