Pywinauto用法-Log.py
https://www.pythonf.cn/read/127079?ivk_sa=1024320u
Log.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import os
import time
class Logger(object):
def __init__(self,filename="Default.log",add_flag=True, stream=sys.stdout):
self.terminal = stream
self.filename=filename
self.add_flag=add_flag
def write(self,message):
if self.add_flag:
with open(self.filename,'a') as log:
self.terminal.write(message)
log.write(message)
else:
with open(self.filename,'w') as log:
self.terminal.write(message)
log.write(message)
def flush(self):
pass
def LoggerPrint():
filename="Default.log"
if os.path.exists(filename):
with open(filename, 'a') as log:
log.seek(0)
log.truncate()
else:
pass
sys.stdout = Logger('./Default.log', sys.stdout)
print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())))