<s>[INST] Evaluate $\int_0^\infty \frac{(\ln x)^2}{x^2+4} \ dx$ using complex analysis. Evaluate $\int_0^\infty \frac{(\ln x)^2}{x^2+4} \ dx$.  This is the last question in our review for complex analysis.  Hints were available upon request, but being the student I am, I waited until the last minute to do this.  Can anyone give a detailed answer?  It would greatly appreciated.  This is part of our residue theorem review, which is how we were taught to evaluate such integrals.
 [/INST] Consider the contour integral
$$\oint_C dz \frac{\log^3{z}}{z^2+4} $$
where $C$ is a keyhole contour about the positive real axis, with outer radius $R$ and inner radius $\epsilon$.  The contour integral is then equal to
$$\int_{\epsilon}^R dx \frac{\log^3{x}}{x^2+4} +i R \int_0^{2 \pi} d\theta \, e^{i \theta} \frac{\log^3{(R e^{i \theta})}}{R^2 e^{i 2 \theta}+4} \\ + \int_R^{\epsilon} dx \, \frac{(\log{x}+i 2 \pi)^3}{x^2+4} + i \epsilon \int_{2 \pi}^0 d\phi \, e^{i \phi} \frac{\log^3{(\epsilon e^{i \phi})}}{\epsilon^2 e^{i 2 \phi}+4}$$
As $R \to \infty$ the second integral vanishes as $2 \pi R \log^3{R}/(R^2-4)$; as $\epsilon \to 0$, the fourth integral vanishes as $(\pi/2) \epsilon \log^3{\epsilon}$.  In this limit, then, the contour integral is
$$-i 6 \pi\int_0^{\infty} dx \frac{\log^2{x}}{x^2+4} + 12 \pi^2 \int_0^{\infty} dx \frac{\log{x}}{x^2+4} + i 8 \pi^3 \int_0^{\infty} \frac{dx}{x^2+4}$$
The third integral is familiar, and is equal to $i 8 \pi^3 (\pi/4) = i 2 \pi^4$.  The second integral is evaluated in a similar manner:
$$\begin{align}\int_0^{\infty} dx \frac{\log^2{x}-(\log{x}+i 2 \pi)^2}{x^2+4} &= -i 4 \pi\int_0^{\infty} dx \frac{\log{x}}{x^2+4} + 4 \pi^2 \int_0^{\infty} \frac{dx}{x^2+4} \\ &=-i 4 \pi\int_0^{\infty} dx \frac{\log{x}}{x^2+4} +\pi^3 \\ &= \underbrace{i 2 \pi \frac14 \left ( -i  (\log{2}+i \frac{\pi}{2})^2+ i (\log{2}+i \frac{3\pi}{2})^2\right )}_{\text{residue theorem}}\\ &= i \pi (-\pi \log{2} - i  \pi^2)\\ &=  \pi^3 - i  \pi^2 \log{2}\end{align}$$
so that
$$\int_0^{\infty} dx \frac{\log{x}}{x^2+4} = \frac{\pi}{4} \log{2}$$
Therefore, by the residue theorem,
$$\begin{align}-i 6 \pi\int_0^{\infty} dx \frac{\log^2{x}}{x^2+4} + 3 \pi^3 \log{2} + i 2 \pi^4 &= i 2 \pi \frac14 \left ( -i  (\log{2}+i \frac{\pi}{2})^3+ i (\log{2}+i \frac{3\pi}{2})^3\right ) \\ &= 3 \pi^3 \log{2} + i \left (\frac{13 \pi^4}{8}-\frac{3 \pi^2}{2} \log^2{2} \right )  \end{align} $$
Therefore
$$\int_0^{\infty} dx \frac{\log^2{x}}{x^2+4} = \frac{\pi^3}{16} + \frac{\pi}{4} \log^2{2} $$
</s>