Optimized log writing.