Pole lying in the middle of a logarithm's branch cut in $\int_{-\infty}^{\infty} dz \frac{\ln(a+z^2)}{1+z^2}$ Consider the integral, for $a\geq0$,
$$I = \int_{-\infty}^{\infty} dz \frac{\ln(a+z^2)}{1+z^2} = 2 \pi \ln(1+\sqrt{a})$$
This is straightforward to do with real methods via differentiation with respect to $a$, partial fraction decomposition, and integration with respect to $a$. My question is about evaluating this integral directly using a contour integral in the complex plane. I am running into a problem for $a\leq1$ where the pole $z=i$ lies directly in the middle of the branch cut, yielding an extra, seemingly spurious, imaginary contribution.

I will define $\ln(z)$ to have a branch cut on the negative real axis. Looking in the upper half plane, the branch point $z = \sqrt{a} i$ yields a branch cut in $\ln(a+z^2)$ moving up the imaginary axis (this follows since the imaginary part of $a+x^2$ changes sign on crossing the imaginary axis, and the real part is non-positive.)
Consider the integral for $a>1$, and consider the following contour:

The contour integral via the pole at $z=i$ evaluates to $\pi \ln(a-1)$. Looking at the different contributions, and noting that the arc does not contribute because the function decays quickly enough, we have
$$\pi \ln(a-1) = I + \int_{\sqrt{a}}^\infty i dy \frac{2\pi i}{1-y^2}$$
Here, the second contribution on the right hand side comes from the vertical lines on the sides of the branch cut. It is straightforwardly evaluated as $\pi \ln(\frac{\sqrt{a}-1}{\sqrt{a}+1}$).
Solving for $I$ yields, as anticipated,
$$I = 2\pi \ln(1+\sqrt{a})$$

However, I'm having much more trouble for $a \leq i$, for which the pole lies in the middle of the branch cut. I keep getting an extra contribution!

The contour integral now evaluates to zero, but there are significant contributions from the small semicircle arcs about the pole. My trouble is that the small semicircle arcs are on different sides of the branch cut and hence contribute different amounts. I find
$$0 = I + PV \int_{\sqrt{a}}^\infty i dy \frac{2\pi i}{1-y^2} + (-\pi \ln(a-1)/2) + (-\pi \ln(a-1)/2 \color{red}{+ 2 \pi i (-\pi i)/(2i)}  ) $$
From left to right, I have the original integral, the contribution from the vertical parts of the contour, the right small semicircle, and the left small semicircle. The left small semicircle is on the side of the branch cut with an extra $2 \pi i$ contribution from the log, which gives the extra red contribution. Without the red contribution, I get the right answer after rearranging and simplifying. With the red contribution, I suffer an imaginary contribution that yields an incorrect result for $I$.

How does one properly handle a pole lying in the middle of a (logarithm's) branch cut? Am I missing another imaginary contribution that cancels with the one in red?
 A: My choice of the branch cut on the negative real axis means the jump in phase is between $\pi$ and $-\pi$. Here, $1+z^2$ has a phase of $\pi$ on the right edge of the branch cut and a phase of $-\pi$ on the left side of the branch cut.  Correspondingly,
$$0 = I + PV \int_{\sqrt{a}}^\infty i dy \frac{2\pi i}{1-y^2} + (-\pi \ln(a-1)/2 \color{red}{+ \pi i (-\pi i)/(2i)}) + (-\pi \ln(a-1)/2 \color{red}{- \pi i (-\pi i)/(2i)})$$
This resolves the discrepancy, as the two contributions in red cancel.
The reason I made my mistake is that the difference across a branch cut of a log is $2 \pi i$, and I'm quite used to taking my branch cuts on the positive real axis for which the phase goes from $0$ to $2\pi$, so I stuck in a $2\pi i$ without thinking.

This more careful bookkeeping unearthed a second mistake I made in the question. The contribution $\int_{\sqrt{a}}^\infty i dy \frac{2\pi i}{1-y^2}$ should instead be $\int_{\sqrt{a}}^\infty i dy \frac{-2\pi i}{1-y^2}$, since the left hand side of the branch cut has a phase that is lower by $2 \pi i$ relative to the right hand side, not higher.
Everything works out in the end, since $\int_{\sqrt{a}}^\infty i dy \frac{2\pi i}{1-y^2} = -\pi \ln(\frac{\sqrt{a}-1}{\sqrt{a}+1})$, which is negative what I had written; two wrongs had made a right in my first calculation.
