Updated the writelog function