You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
caveman/logger.py

32 lines
695 B
Python

import os
def getstamp():
os.system("date >> stamp")
with open("stamp") as f:
s = f.read()
os.remove("stamp")
return s
class BotLogger:
def __init__(self, filename):
if os.path.exists(filename):
n = 0
while os.path.exists(filename + "." + str(n)):
n += 1
filename = filename + "." + str(n)
self.fn = filename
def log(self, caller, text):
info = getstamp().strip() + " --> " + caller + ": " + text
with open(self.fn, "a+") as f:
f.write("\n" + info + "\n")
print(info)
def getlog(self):
with open(self.fn) as f:
return f.read()