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|}}$$
A: Another way to do this is by integrating $\dfrac{\log(z)}{z^2+a^2}$ from $-R$ to $R$ over the real axis while avoiding the branch point at $z = 0$ using a half circle of radius $\epsilon$ and then complete the contour by returning from $R$ to $-R$ over a counterclockwise half circle with radius $R$ and center the origin in the upper half plane. Here you define $\log(z)$ by putting the branch cut along some line that moves from the origin into the lower half plane. For real negative $x$, we then have $\log(x) = \log(|x|) + i\pi$.
It's easy to prove that the integral over the half circle tends to zero in the limit of $R\to\infty$, and that the limit of $\epsilon\to 0$ exists. The residue theorem then yields the result:
$$\int_{-\infty}^{\infty}\frac{\log(x) dx}{x^2+a^2}= 2\pi i\lim_{z\to i |a|}(z-i |a|)\frac{\log(z)}{z^2+a^2}=\frac{\pi\log(i|a|)}{|a|} =\frac{\pi\log(|a|)}{|a|}  + i\frac{\pi^2\log(|a|)}{2|a|}$$
where we've used that $\log(i) = \log\left[\exp(i\frac{\pi}{2})\right]= i\frac{\pi}{2}$ which follows from the way we've defined the logarithm by putting the branch cut in the lower half plane, this makes the argument of $i$ equal to $\dfrac{\pi}{2}$.
The result then follows by writing:
$$\int_{-\infty}^{\infty}\frac{\log(x) dx}{x^2+a^2}= \int_{-\infty}^{0}\frac{\log(x) dx}{x^2+a^2} + \int_{0}^{\infty}\frac{\log(x) dx}{x^2+a^2}$$
 and
$$\int_{-\infty}^{0}\frac{\log(x) dx}{x^2+a^2} = \int_{0}^{\infty}\frac{\left[\log(x)+i\pi\right] dx}{x^2+a^2}$$
This then yields the answer:
$$\int_{0}^{\infty}\frac{\log(x) dx}{x^2+a^2} = \frac{\pi\log(|a|)}{2|a|} $$
