Factor out log directory calculation code, in preparation for changing how it works