Added encoding to logging function