Calculate Integral using residue theorem

For any $a>0$, through the substitution $x=a e^t$ we have

$$ I(a) = \int_{0}^{+\infty}\frac{\log x}{a^2+x^2}\,dx = \frac{1}{2a}\int_{-\infty}^{+\infty}\frac{\log a+ t}{\cosh t}\,dt \tag{1}$$ and $\frac{t}{\cosh t}$ is an odd integrable function over $\mathbb{R}$. It follows that $$ I(a) = \frac{\log a}{2a}\int_{-\infty}^{+\infty}\frac{dt}{\cosh t}=\frac{\log a}{2a}\left[2\arctan\tanh\frac{t}{2}\right]^{+\infty}_{-\infty}=\color{red}{\frac{\pi\log a}{2a}} \tag{2} $$ without even resorting to the residue theorem, but just exploiting symmetry.


Along the real axis, we have

$$\begin{align} \int_{-R}^R \frac{\log(x)}{x^2+a^2}\,dx&=\int_{-R}^0 \frac{\log(x)}{x^2+a^2}\,dx+\int_0^{R} \frac{\log(x)}{x^2+a^2}\,dx\\\\ &=\int_0^R \frac{\log(-x)+\log(x)}{x^2+a^2}\,dx\\\\ &=2\int_0^R \frac{\log(x)}{x^2+a^2}\,dx+i\pi\int_0^R\frac{1}{x^2+a^2}\,dx\\\\ &=2\int_0^R \frac{\log(x)}{x^2+a^2}\,dx+\frac{i\pi\arctan(R/a)}{a}\tag1 \end{align}$$

As $R\to \infty$, we find that

$$\int_{-\infty}^\infty \frac{\log(x)}{x^2+a^2}\,dx=2\int_0^\infty \frac{\log(x)}{x^2+a^2}\,dx+\frac{i\pi^2}{2a}\tag 2$$

Setting $(2)$ equal to $\frac{\pi \log(a)}{a}+i\frac{\pi^2}{2a} $, we find that

$$\int_0^\infty \frac{\log(x)}{x^2+a^2}\,dx=\frac{\pi \log(a)}{2a}$$


I thought it might be instructive to evaluate the integral of interest using real analysis only. To that end, we enforce the substitution $x\to a/x$ to find that

$$\int_0^\infty \frac{\log(x)}{x^2+a^2}\,dx=\frac1a \int_0^\infty \frac{\log(a)-\log(x)}{x^2+1}\,dx \tag2$$

For $a=1$, we see from $(2)$ that $\int_0^\infty \frac{\log(x)}{x^2+1}\,dx =0$. Thus, solving $(2)$ for integral of interest, and using $\int_0^\infty \frac{\log(x)}{x^2+1}\,dx =0$, we find that

$$\int_0^\infty \frac{\log(x)}{x^2+a^2}\,dx=\frac{\pi \log(a)}{2a}$$

as expected!


Using a semi-circular contour in the upper half plane that rests on the real axis we obtain

$$\int_0^\infty \frac{1}{x^2+a^2} \; dx = \frac{1}{2} \int_{-\infty}^\infty \frac{1}{x^2+a^2} \; dx \\ = \frac{1}{2} \times 2\pi i \frac{1}{2\times ai} = \frac{\pi}{2a}.$$

Next using a keyhole contour with the slot on the positive real axis and the branch of the logarithm where $0\le \arg\log z\lt 2\pi$ (branch cut on the positive real axis) we obtain integrating

$$f(z) = \frac{\log^2 z}{z^2+a^2}$$

the integrals

$$\int_0^\infty \frac{\log^2 x}{x^2+a^2} \; dx + \int_\infty^0 \frac{\log^2 x + 4\pi i \log x - 4\pi^2 }{x^2+a^2} \; dx \\ = 2\pi i \left(\frac{\log^2(ai)}{2\times ai} + \frac{\log^2(-ai)}{2\times -ai}\right).$$

This yields

$$-4\pi i \int_0^\infty \frac{\log x}{x^2+a^2} \; dx + 4\pi^2 \times \frac{\pi}{2a} = \frac{\pi}{a} ((\log a + \pi i/ 2)^2 - (\log a + 3\pi i/2)^2) \\ = \frac{\pi}{a} (\log a \times \pi i (1-3) + \pi^2 (-1/4 + 9/4)).$$

We thus obtain

$$4\pi i \int_0^\infty \frac{\log x}{x^2+a^2} \; dx = 4\pi^2 \times \frac{\pi}{2a} - \frac{\pi}{a} (-\log a \times 2\pi i + 2 \pi^2) \\ = \frac{\pi}{a} \log a \times 2\pi i.$$

Dividing by $4\pi i$ we finally obtain

$$\bbox[5px,border:2px solid #00A000]{ \frac{\pi}{2a}\log a.}$$

The bounds on the circular components that we used here were

$$2\pi R \times \frac{\log^2 R}{R^2} \rightarrow 0 \quad\text{and}\quad 2\pi \epsilon \times \frac{\log^2 \epsilon}{a^2} \rightarrow 0.$$