Refactor: extract logEventsForCommand