执行从 Robot Framework 中进行,其中Test.py
已作为库导入并testLog()
正在执行,而后者又导入Logger.py
并调用LogMessage()
.
测试.py
import Logger
def testLog():
Logger.LogMessage("This is the first line of the log file.")
Logger.LogMessage("This is the second line of the log file.")
Logger.LogMessage("This is the third line of the log file.")
记录器.py
import logging
def LogMessage(message):
LOG_FILENAME = "C://Log_Details".log"
logger = logging.getLogger()
logFileHandler = logging.FileHandler(LOG_FILENAME)
logger.addHandler(logFileHandler)
Log_Details.log
This is the first line of the log file.
This is the second line of the log file.
This is the second line of the log file.
This is the third line of the log file.
This is the third line of the log file.
This is the third line of the log file.
RIDE 中的消息日志部分在执行期间只记录每行一次,但名为的文件Log_details.log
会多次打印它们,即第一行记录一次,第二行记录两次,依此类推。