Skip to content

Instantly share code, notes, and snippets.

@theskumar
Last active August 29, 2015 14:04
Show Gist options
  • Save theskumar/2b3b12642ea33b2ca195 to your computer and use it in GitHub Desktop.
Save theskumar/2b3b12642ea33b2ca195 to your computer and use it in GitHub Desktop.
An independent logger class in python
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