<s>[INST] Value of this definite integral $\int_{0}^{\infty} \frac{ \ln(x)}{x^2+2x+4} dx $ So I came across this question on brilliant.org and didn't know how to go about it:
$$\int_{0}^{\infty} \frac{ \ln(x)}{x^2+2x+4} dx $$
I tried to complete the squares in the denominator and then use a trigonometric substitution (with tan) but I didn't get anything beyond that. 
How do I do it? Do we need to differentiate under the integral sign here?
 [/INST] As mentioned above, use a keyhole contour in the complex plane, which we'll call $C$.  Here though you should consider the contour integral
$$\oint_C dx \frac{\log^2{z}}{z^2+2 z+4} $$
I will leave it to the reader to show that the integral vanishes over the circular portions of $C$; we are thus left with the contour integral equaling
$$\int_0^{\infty} dx \frac{\log^2{x}-(\log{x}+i 2 \pi)^2}{x^2+2 x+4} = -i 4 \pi \int_0^{\infty} dx\frac{\log{x}}{x^2+2 x+4} + 4 \pi^2 \int_0^{\infty} \frac{dx}{x^2+2 x+4}$$
Now, the integral on the right we need to know as well.  We may evaluate that any way we wish, but let's stick to this formalism.  This integral may be evaluated using the same contour and the residue theorem.  Let
$$R_n = \sum_k \operatorname*{Res}_{z=z_k} \frac{\log^{n+1}{z}}{z^2+2 z+4}$$
for $n=0,1$.  That is,
$$\oint_C dz \frac{\log^{n+1}{z}}{z^2+2 z+4} = i 2 \pi R_n$$
Then from the above, you may show that
$$\int_0^{\infty} dx\frac{\log{x}}{x^2+2 x+4} = i \pi R_0 - \frac12 R_1$$
Note that the poles of the integrands are at $z_1=2 e^{i 2 \pi/3}$ and $z_2 = 2 e^{i 4 \pi/3}$.  Note that we must use these arguments because of how we defined the contour.
We mat deduce that
$$R_0 = \frac{\log{2}+i 2 \pi/3}{i 2 \sqrt{3}} + \frac{\log{2}+i 4 \pi/3}{-i 2 \sqrt{3}} = -\frac{\pi}{3 \sqrt{3}}$$
$$R_1 = \frac{(\log{2}+i 2 \pi/3)^2}{i 2 \sqrt{3}} + \frac{(\log{2}+i 4 \pi/3)^2}{-i 2 \sqrt{3}} = -\frac{2 \pi \log{2}}{3 \sqrt{3}} - i \frac{2 \pi^2}{3 \sqrt{3}}$$
Putting it all together, the imaginary pieces cancel and we get
$$\int_0^{\infty} dx\frac{\log{x}}{x^2+2 x+4} = \frac{\pi \log{2}}{3 \sqrt{3}}$$
</s>