Created
March 15, 2018 19:12
-
-
Save neutronstriker/89df3f48a03914c443870019a62085f1 to your computer and use it in GitHub Desktop.
write prints to console and log
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 | |
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