import time
class Logger:
def __init__(self, filename):
self.filename = filename
def __call__(self, string):
file = open(self.filename, 'a')
file.write('[' + time.asctime() + '] ')
file.write(string + '\n')
file.close()
log = Logger('logfile.txt')
log('Starting program')
log('Trying to divide 1 by 0')
print 1 / 0
log('The division succeeded')
log('Ending program')
|