[Python] Simple Print and Log Python Function (def)

import os
from datetime import datetime

## CLEAR LOG FILE ##
logfile = "my.log"
if os.path.exists(logfile): os.remove(logfile)

def plog(string):
  output = (str(datetime.now()).split('.',1)[0] + ": " + string)
  print(output)
  open(logfile,'a').write(output + "\n")


To use, simply:

plog("My text to print and log")

Comments