in reply to writing to log file
You'll want to read about the system command : system and perhaps reconsider your log file format to include the date and time at the beginning of each line. Read the sprintf command documentation too.