added  write_log function