extract this entire bit in a helper method, so that it can be reused later (e.g. in the open-log-stream command)