【自动化测试】写一个简单的控制台日志输出
1.输出控制台日志打印的代码如下:
import sys import datetime class Logger(object): tree_log = "url"def __init__(self, stream=sys.stdout): now = datetime.datetime.now().date() filename = str(now) + '.log' self.terminal = stream self.log = open(self.tree_log + filename, 'a') def write(self, message): self.terminal.write(message) self.log.write(message) def flush(self): pass
2.如果想让服务器和日志多线程运行话
def threadLog(): sys.stdout = outPutLog.Logger() thread = threading.Thread(target=threadLog) thread.start()
一切博文基本原创,谢谢