move code to function `spawn_logger_thread`