TITLE: Calculate Integral using residue theorem
QUESTION [6 upvotes]: I want to verify the following result using the residue theorem:

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

Here are my ideas:  
At first I might want to show that this function is in fact a well defined improper Riemann integral, but I didn't come up with any nice solution yet.  
I want to integrate the function $f(z) := \frac{\log(z)}{z^2+a^2}$ along the contour $C:= \gamma_1 \cup \gamma_2 \cup \gamma_3 \cup \gamma_4$ constisting of to semicircles with center at 0 around the upper half plane and radius $R$ and $\epsilon$ (resp.) as well as the intervals $[-R, -\epsilon]$ and $[\epsilon, R]$.  
For the complex logarithm, use the branch $\log z = \log|z| + i\theta, \theta \in [-\pi/2, 3\pi/2)$ so we don't get any problems on the real line (is this choice correct?).
Note that I have one pole in my contour, namely $z = ia$. The Residue theorem yields $$\int_C f(z) dz= 2\pi i \text{ Res}(f, ia) = 2\pi i\lim_{z\to ia}(z-ia) \frac{\log z}{(z-ia)(z+ia)} = 2\pi i\frac{\log(ia)}{2ia} = \pi \frac{\log(a)+ i\pi/2}{a}$$
Proceeding, we choose the following parametrizations:
$$\gamma_1 : [-R,0]  \to \mathbb C, \quad t\mapsto -\frac{\epsilon t}{R} + (t-\epsilon) \\ \gamma_2 : [0, R] \to \mathbb C, \quad t\mapsto -\frac{\epsilon t}{R} + (\epsilon+t) \\ \gamma_3: [0, \pi]\to \mathbb C, \quad t\mapsto \epsilon e^{it} \\ \gamma_4:[0,\pi] \to \mathbb C, \quad t \mapsto Re^{it}$$
Now here's what I am unsure about. To show that the big and the small circle vanish as $R\to \infty$ and $\epsilon \to 0$ is not too hard, but how to deal with the other integrals?
Can I just say 
$$\int_{\gamma_1} f(z)dz = \int_0^R \frac{\log(-\frac{\epsilon}{R}t+\epsilon+t)}{(-\frac{\epsilon}{R}t + \epsilon + t)^2 + a^2}(\frac{\epsilon}{R}+1)dt \xrightarrow{\epsilon \to 0} \int_0^R \frac{\log t}{t^2 + a^2}dt$$ 
or what kind of reasoning should be used to interchange limit and integral?Also, I then finally I get $$\int_0^\infty \frac{\log(x)}{x^2+a^2}dx = \pi \frac{\log a + i\frac{\pi}{2}}{2a}$$
almost what I want, but where does $i\pi /2$ come from?
Thanks in advance!

REPLY [2 votes]: 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.$$