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?