flush streams and ensure new line before prefix