Using contour integration to evaluate $\int_{0}^{\infty} \frac{2 \cos (x) \ln (x) + \pi \sin (x)}{x^2+4} \, \mathrm dx$ I want to use contour integration to show that $$\int_{0}^{\infty} \frac{2 \cos (x) \log (x) + \pi \sin (x)}{x^2+4} \, \mathrm  dx = \frac{\pi \log (2)}{2e^{2}}.$$
The recommendation in the textbook I'm reading is to integrate the function $$f(z) = \frac{e^{iz} \log(-iz)}{z^{2}+4}$$ around an indented contour that consists of the real axis from $-R$ to $R$, along with the upper half of the circle $|z|=R$.
The fact that $f(z)$ involves $\log(-iz)$ and not simply $\log (z)$ makes me a bit uneasy.
I think we would want to place the branch cut along the negative imaginary axis so that it doesn't intersect the contour.
Would that mean $- \pi  < \arg(-iz) \le  \pi$?
EDIT:
I converted the rest of my question into an answer.
 A: I think this is a bit backwards. If you want the branch cut to be downwards (-ve imaginary axis, located at $\arg z = -\pi/2,3\pi/2,\cdots$) then you want a $(-\pi/2,3\pi/2)$ range for $\arg z$, agreed.
Now the discontinuity is at $-i$. Hence $\arg(-iz)$ is discontinuous at $(-i)(-i)=-1$. Accordingly we will take a $(-\pi,\pi)$ type interval.


*

*For $\mathbb R \ni z>0$ we have $\arg(-i\times z)=\arg(-i) = -i\pi/2$.

*For $\mathbb R \ni z<0$ we have $\arg(-i\times z)=\arg(i) = +i\pi/2$.


Your values are impossible, in that they are not a multiple of $2\pi$ out from the standard arguments.
You should be able to get the answer using these.
A: Revisiting this question, I see no reason why we couldn't simply integrate the function $$f(z) = \frac{e^{iz} \log (z)}{z^{2}+4}$$ around the same contour with the branch cut in the same location.
The only extra step would be extracting the real part of the result.
By Jordan's lemma (or the estimation lemma), $ \int f(z) \, \mathrm dz $ vanishes along the upper half of the circle $|z|=R$ as $R \to \infty$.
Therefore,
$$ \begin{align} &\int_{-\infty}^{0} \frac{e^{ix} (\log |x| + i \pi)}{x^{2}+4} \, \mathrm  dx + \int_{0}^{\infty} \frac{e^{ix} \log (x)}{x^{2}+4} \, \mathrm  dx \\ &= \int_{0}^{\infty} \frac{e^{-iu} (\log (u) + i \pi)}{u^{2}+4} \, \mathrm du + \int_{0}^{\infty} \frac{e^{ix} \log (x)}{x^{2}+4} \, \mathrm dx \\ &= \int_{0}^{\infty} \frac{(\cos (x) - i \sin (x)) (\log (x) + i \pi)+ (\cos (x) + i \sin (x))\log (x)}{x^{2}+4}  \, \mathrm dx \\ &= \int_{0}^{\infty} \frac{2 \cos (x) \log (x)+ \pi \sin (x)}{x^{2}+4} \, \mathrm  dx + i \pi \int_{0}^{\infty} \frac{\cos (x)}{x^{2}+4} \, \mathrm dx \\ &= 2 \pi i \ \text{Res}[f(z),2i] \\ &= 2 \pi i \left(\frac{e^{-2} (\log (2) + \frac{i \pi}{2})}{4i} \right) \\&= \frac{\pi \log (2)}{2e^{2}} + i \frac{\pi^{2}}{4e^{2}} .\end{align}$$
By equating the real parts on both sides of the equation,we arrive at the answer.
