Fetch truncate logs

continuation of #9222 and #6662, closes #6630
write a temp file and rename it