Q:

Contour integration of $\frac{\log( x)}{x^2+a^2}$

How do I intgrate $\int_0^{\infty}\frac{\log( x)}{x^2+a^2} \,dx$ using contour integration? Simple integration is easy but I can't understand contour integration. Please help!

A:

A standard approach to evaluating the integral $\int_0^\infty \frac{\log(x)}{x^2+a^2}\,dx$ using contour integration is to analyze the integral $\oint_C \frac{\log^2(z)}{z^2+a^2}\,dz$, where $C$ is the classical "keyhole" contour with the keyhole taken along the positive real axis.
To that end, we choose to cut the complex plane along the positive real axis such that
$$\log(z)=\log(|z|)+i\arg (z)$$
where $0\le \arg(z)<2\pi$.
With this choice of branch cut, $\log(z)=\log(x)$ as we approach the real axis from the first quadrant and $\log(z)=\log(x)+i2\pi$ as we approach from the fourth quadrant. 

From the reside theorem we have
$$\begin{align}
\oint_C \frac{\log^2(z)}{z^2+a^2}\,dz&=2\pi i \text{Res}\left( \frac{\log^2(z)}{z^2+a^2}, z=\pm ia\right)\\\\
&=2\pi i \left(\frac{\log^2(|a|e^{i\pi/2})}{i2|a|}+\frac{\log^2(|a|e^{i3\pi/2})}{-i2|a|} \right)\\\\
&=\frac{\pi}{|a|}\left(2\pi^2 -i2\pi \log(a)\right)\tag 1
\end{align}$$

Integration over $C$ can be decomposed as
$$\begin{align}
\oint_C \frac{\log^2(z)}{z^2+a^2}\,dz&=\int_\epsilon^R \frac{\log^2(x)}{x^2+a^2}\,dx-\int_\epsilon^R \frac{(\log(x)+i2\pi)^2}{x^2+a^2}\,dx\\\\
&+\int_0^{2\pi}\frac{\log^2(Re^{i\phi})}{(Re^{i\phi})^2+a^2}\,iRe^{i\phi}\,d\phi-\int_0^{2\pi}\frac{\log^2(\epsilon e^{i\phi})}{(\epsilon e^{i\phi})^2+a^2}\,i\epsilon e^{i\phi}\,d\phi\\\\
&=-i4\pi \int_\epsilon^R \frac{\log(x)}{x^2+a^2}\,dx+4\pi^2 \int_\epsilon^R \frac{1}{x^2+a^2}\,dx\\\\
&+\underbrace{\int_0^{2\pi}\frac{\log^2(Re^{i\phi})}{(Re^{i\phi})^2+a^2}\,iRe^{i\phi}\,d\phi}_{\to 0\,\text{as}\,R\to \infty}-\underbrace{\int_0^{2\pi}\frac{\log^2(\epsilon e^{i\phi})}{(\epsilon e^{i\phi})^2+a^2}\,i\epsilon e^{i\phi}\,d\phi}_{\to 0\,\text{as}\,\epsilon \to 0}\tag2
\end{align}$$

Letting $R\to \infty$ and $\epsilon \to 0$ in $(2)$ and equating the real and imaginary parts of the result to $(1)$ yields

$$\bbox[5px,border:2px solid #C0A000]{\int_0^\infty \frac{\log(x)}{x^2+a^2}\,dx=\frac{\pi\log(|a|)}{2|a|}}$$

and as a bonus 
$$\bbox[5px,border:2px solid #C0A000]{\int_0^\infty \frac{1}{x^2+a^2}\,dx=\frac{\pi}{2|a|}}$$

