Addded code for log writing