Added write log function