def Log(self, eventType, dataList):
'''
Create an entry in the log file. Each entry will look like:
timestamp\tevent\tdata1\tdata2 <etc>\n
where:
timestamp = integer seconds since the UNIX epoch
event = string identifying the event
data1..n = individual data fields, as appropriate for each event type.
To avoid maintenance issues w/r/t enormous log files, the log filename
that's stored in the settings file is passed through datetime.strftime()
so we can expand any format codes found there against the current date/time
and create e.g. a monthly log file.
'''
now = int(time())
today = datetime.fromtimestamp(now)
# if there's no explicit log file path/name, we create one
# that's the current year & month.
fileName = self.settings.logFilePath
if not fileName:
fileName = "%Y-%m.txt"
self.settings.logFilePath = fileName
path = self.GetPath(fileName)
path = today.strftime(path)
with open(path, "a+t") as f:
f.write("{0}\t{1}\t".format(now, eventType))
f.write("\t".join(dataList))
f.write("\n")
评论列表
文章目录