clean up logging with a contextmanager