Made the log thread safe, and added a task for loop function