def log(self, location, text, timestamp=None, force=False, subfolder=None, mode='a'):
if not timestamp:
timestamp = datetime.utcnow()
if self.lock or not (force or self.should_log(location)):
return
path = PATH_LIST.copy()
entry = [timestamp.strftime(TIMESTAMP_FORMAT)]
if type(location) is discord.Server:
path += [location.id, 'server.log']
elif type(location) is discord.Channel:
serverid = location.server.id
entry.append('#' + location.name)
path += [serverid, location.id + '.log']
elif type(location) is discord.PrivateChannel:
path += ['direct', location.id + '.log']
else:
return
if subfolder:
path.insert(-1, str(subfolder))
text = text.replace('\n', '\\n')
entry.append(text)
fname = os.path.join(*path)
handle = self.gethandle(fname, mode=mode)
await handle.write(' '.join(entry) + '\n')
评论列表
文章目录