Skip to content

Instantly share code, notes, and snippets.

@neutronstriker
Created March 15, 2018 19:12
Show Gist options
  • Save neutronstriker/89df3f48a03914c443870019a62085f1 to your computer and use it in GitHub Desktop.
Save neutronstriker/89df3f48a03914c443870019a62085f1 to your computer and use it in GitHub Desktop.
write prints to console and log
import time
errorLogFileName = 'logfile.log'
ferrlog = open(errorLogFileName,'w')
def write2ErrorLog(inputval):
data = str(inputval)
timeStamp = time.strftime('%Y-%m-%d,%H:%M:%S')
if data[0] == '\n':
print '\n'+timeStamp+' : '+data[1:]+'\n'
if ferrlog.closed == False:
ferrlog.write('\n'+timeStamp+' : '+data[1:]+'\n')
else:
print timeStamp+' : '+data+'\n'
if ferrlog.closed == False:
ferrlog.write(timeStamp+' : '+data+'\n')
if ferrlog.closed == False:
ferrlog.flush()
write2ErrorLog("test")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment