Definite integral $\int_{-\infty}^\infty \frac{\log(x^2+a^2)}{(x-ib)^2} dx$ How can I evaluate the integral
$$\int_{-\infty}^\infty \frac{\log(x^2+a^2)}{(x-ib)^2} dx?$$
Here $a, b$ are positive real constants. When I plug this expression in MATLAB, I obtain the answer as
$$ - \frac{\mathrm{log}\!\left(x - a\, \mathrm{i}\right)\, \mathrm{i}}{a - b} - \frac{\mathrm{log}\!\left(a^2 + x^2\right)\, \mathrm{i}}{b + x\, \mathrm{i}} + \frac{\mathrm{log}\!\left(x + a\, \mathrm{i}\right)\, \mathrm{i}}{a + b} + \frac{b\, \mathrm{log}\!\left(x - b\, \mathrm{i}\right)\, 2\, \mathrm{i}}{a^2 - b^2}$$
for the indefinite integral. However I have a problematic complex logarithm, which is ambiguous depending on the branch cut. Furthermore, the MATLAB does not give an answer of the definite integral for the integration range $(-\infty, \infty)$.
This integral is motivated from physics, especially when computing a Feynman diagram.
 A: Let $f \colon (0,\infty)^2 \to \mathbb{C}, \, f(a,b) = \int_{-\infty}^\infty \frac{\log(a^2+x^2)}{(x-\mathrm{i} b)^2} \, \mathrm{d} x$. We can get rid of $a$ by letting $x = a t$ and using the result $\int_{-\infty}^\infty \frac{\mathrm{d} t}{(t-\mathrm{i} c)^2} = 0$ for $c > 0$:
$$ f(a,b) = \frac{1}{a} \int \limits_{-\infty}^\infty \frac{2 \log(a) + \log(1+t^2)}{\left(t - \mathrm{i} \frac{b}{a} \right)^2} \, \mathrm{d} t = \frac{1}{a} \int \limits_{-\infty}^\infty \frac{\log(1+t^2)}{\left(t - \mathrm{i} \frac{b}{a} \right)^2} \, \mathrm{d} t \, . $$
Integration by parts then yields
\begin{align}
f(a,b) &= \frac{2}{a} \int \limits_{-\infty}^\infty \frac{t}{(1+t^2)\left(t - \mathrm{i} \frac{b}{a}\right)} \, \mathrm{d} t = \frac{2}{a} \int \limits_{-\infty}^\infty \frac{t \left(t + \mathrm{i} \frac{b}{a}\right)}{(1+t^2)\left(\frac{b^2}{a^2} + t^2\right)} \, \mathrm{d} t \\
&= \frac{2}{a} \int \limits_{-\infty}^\infty \frac{t^2}{(1+t^2)\left(\frac{b^2}{a^2} + t^2\right)} \, \mathrm{d} t \, ,
\end{align}
since the imaginary part of the integrand is an odd function. For $a \neq b$ we can now use partial fractions to compute the remaining integral, while for $a = b$ integrating by parts once more does the trick. The final result in either case is
$$ f(a,b) = \frac{2}{a} \frac{\pi}{1 + \frac{b}{a}} = \frac{2\pi}{a+b} \, . $$
