This looks like a somewhat messy calculation whichever way you do it. But I think that you are using an awkward contour for the purpose. With the function try taking the contour that goes along the positive real axis from to , then anticlockwise round a complete circle from all the way round to (except that you will now be on a different branch of the log function), then back along the positive real axis from to , and finally clockwise all the way round a circle of radius back to the starting point.