Fix log writing