improved log stats, also guard against potential segv issue with fdopen