add ensure_dir to log directory creation function