0
执行发生于Robot Framework,其中Test.py
已作为库导入并且testLog()
正在执行,后者又导入Logger.py
并调用LogMessage()
。在Python中使用FileHandler多次打印日志
Test.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.")
Logger.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.
在乘坐消息日志部执行期间记录每行只是一次,但名为Log_details.log
的文件会多次打印它们,即第一行会记录一次第二次获得记录两次,依此类推。