Improve encoding handling in logOutput