Skip to content

Instantly share code, notes, and snippets.

@sunilnandihalli
Created January 11, 2016 07:05
Show Gist options
  • Save sunilnandihalli/11ac7ab6766811ccc0bd to your computer and use it in GitHub Desktop.
Save sunilnandihalli/11ac7ab6766811ccc0bd to your computer and use it in GitHub Desktop.
class logger:
def __init__(self,fname=None,copy_to_stdout=True):
self.copy_to_stdout=copy_to_stdout
if fname:
x=datetime.datetime.now()
self.fd = open('%s-%04d%02d%02d%02d%02d.log'%(fname,x.year,x.month,x.day,x.hour,x.minute),'w')
else:
self.copy_to_stdout = False
self.fd = sys.stdout
def log(self,*s):
print >>self.fd,datetime.datetime.utcnow(),s
if self.copy_to_stdout:
print datetime.datetime.utcnow(),s
self.fd.flush()
info_log = logger('info.log')
failed_honest_models = logger('failed_honest_models.log')
failed_smaato_models = logger('failed_smaato_models.log')
not_enough_data_tuples = logger('not_enough_data.log')
processed_data = logger('processed_data.log')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment