TITLE: Integrating this natural log using complex analysis
QUESTION [6 upvotes]: Question: Integrate$$\mathscr{I}=\int\limits_{-\infty}^{\infty}dx\,\frac {\log(1+x^2)}{1+x^2}$$

I tried using a semicircle with radius $R$ with a smaller semicircle detour inside

So we have that$$\oint\limits_{C}dz\, f(z)=\int\limits_r^Rdx\, f(x)+\int\limits_{\gamma_R}dz\, f(z)+\int\limits_{-R}^{-r}dx\,\frac {\log|1+x^2|+i\arg(1+x^2)}{1+x^2}+\int\limits_{\gamma_r}dz\, f(z)$$where $f(z)$ represents the integrand. However, I'm having trouble computing the residue at $z=i$ because the limit leads to infinity.
Are branch cuts required? If so, is it possible for you to walk me through it? I'm not very familiar with them...

REPLY [2 votes]: $\newcommand{\Log}{\operatorname{Log}}\newcommand{\Arg}{\operatorname{Arg}}$EDIT I+II. First there was a silly mistake, but now it is fixed. On the second version, it was just too sinuous. Now it is made straight to the point and short.
These kind of integrals are tricky. For getting started see $\ln(1+x^2)=\text{Re}(2\Log(i+x))$ where $\Log(\cdot) $ is the principal value of the logarithm. So it is reasonable to  consider integrating something with $\Log(i+z)$ instead of something with $\Log(1+z^2)$. Let's integrate the following:
\begin{align}
\oint_C \frac{\Log(i+z)}{1+z^2}\,dz =\int_{C_R}\frac{\Log(i+z)}{1+z^2}\,dz+ \int^R_{-R}\frac{\Log(i+z)}{1+z^2}\,dz
\end{align} 
where $C$ is a semi circle in the upper half plane; $C_R$ is the circle part and the other one is obvious. The branch cut is on $z=-i-\lambda$ with $\lambda\in (0,\infty) $, so we are (luckily) far away from the branch cut.
The only residue inclosed is $z=i$ and therefore the equality:
\begin{align}
\int_{C_R}\frac{\Log(i+z)}{1+z^2}\,dz+ \int^R_{-R}\frac{\Log(i+z)}{1+z^2}\,dz=2\pi i \text{Res}_{z=i} \frac{\Log(i+z)}{1+z^2}
\end{align}
by The Residue Theorem. The integral on $C_R$ will have no contribution when $R\to\infty$. Now lets have a look at the real part of the one on $[-R,R]$:
\begin{align}
\Re\left(\int^R_{-R}\frac{\Log(i+z)}{1+z^2}\,dz\right) &= \frac{1}{2}\int^R_{-R} \frac{\ln(1+x^2)}{1+x^2}\,dx
\end{align}
That is what we have observed in the beginning. Let $R\to \infty$ and we get:
\begin{align}\tag{1}
\frac{1}{2}\int^\infty_{-\infty} \frac{\ln(1+x^2)}{1+x^2}\,dx = \Re\left(2\pi i \text{Res}_{z=i} \frac{\Log(i+z)}{1+z^2}\right)
\end{align}
Doing the residue times $2\pi i$:
\begin{align}
2\pi i\text{Res}_{z=i} \frac{\Log(i+z)}{1+z^2} = 2\pi i\frac{\Log(2i)}{2i}= 2\pi i\frac{\ln(2)+i\frac{\pi}{2}}{2i}=\pi\ln(2)+\frac{i\pi^2}{2}
\end{align}
The real parts in both sides of $(1)$ must be equal and mulitply both sides with $2$ and get the final result:

\begin{align}
\int^\infty_{-\infty}\frac{\ln(1+x^2)}{1+x^2}\,dx =  2\pi\ln(2)
\end{align}