Last active
August 29, 2015 14:04
-
-
Save theskumar/2b3b12642ea33b2ca195 to your computer and use it in GitHub Desktop.
An independent logger class in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
class MessageLogger: | |
""" | |
An independent logger class (because separation is a good thing). | |
""" | |
def __init__(self, file): | |
self.file = file | |
def log(self, message): | |
"""Write a message to the file.""" | |
timestamp = time.strftime("[%H:%M:%S]", time.localtime(time.time())) | |
self.file.write('%s %s\n' % (timestamp, message)) | |
self.file.flush() | |
def close(self): | |
self.file.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment