Quick question on infinite complex integral I'm supposed to find:
$$ \int_0^{\infty} \frac{(\ln x)^2}{1+x^2} dx  $$
I start of by finding:
$$ I_1 = \oint \frac{(\ln z)^2}{1+z^2}  dz  $$
$$ =  \oint \frac{(\ln z)^2}{(z+i)(z-i)} dz $$
Now I take this semi-circle path:

$$ = 2\pi i \times Residue(z=i)  $$
$$= 2\pi i \times \frac{(\ln i)^2}{2i}    $$
$$I_1 =  -\frac{\pi^3}{4} $$
Now applying cauchy's integral:
$$\int_{-R}^{0} + \int_0^R  + \int_\Gamma  =  -\frac{\pi^3}{4}  $$
Taking limits as $R\rightarrow \infty$, $\int_\Gamma \rightarrow 0$
$$\int_{-\infty}^{0} \frac{(\ln x)^2}{1+x^2} + \int_0^\infty  \frac{(\ln x)^2}{1+x^2}  =  -\frac{\pi^3}{4}   $$
Here's what I don't get, why did the solution do this:

 A: $\newcommand{\+}{^{\dagger}}
 \newcommand{\angles}[1]{\left\langle\, #1 \,\right\rangle}
 \newcommand{\braces}[1]{\left\lbrace\, #1 \,\right\rbrace}
 \newcommand{\bracks}[1]{\left\lbrack\, #1 \,\right\rbrack}
 \newcommand{\ceil}[1]{\,\left\lceil\, #1 \,\right\rceil\,}
 \newcommand{\dd}{{\rm d}}
 \newcommand{\down}{\downarrow}
 \newcommand{\ds}[1]{\displaystyle{#1}}
 \newcommand{\expo}[1]{\,{\rm e}^{#1}\,}
 \newcommand{\fermi}{\,{\rm f}}
 \newcommand{\floor}[1]{\,\left\lfloor #1 \right\rfloor\,}
 \newcommand{\half}{{1 \over 2}}
 \newcommand{\ic}{{\rm i}}
 \newcommand{\iff}{\Longleftrightarrow}
 \newcommand{\imp}{\Longrightarrow}
 \newcommand{\isdiv}{\,\left.\right\vert\,}
 \newcommand{\ket}[1]{\left\vert #1\right\rangle}
 \newcommand{\ol}[1]{\overline{#1}}
 \newcommand{\pars}[1]{\left(\, #1 \,\right)}
 \newcommand{\partiald}[3][]{\frac{\partial^{#1} #2}{\partial #3^{#1}}}
 \newcommand{\pp}{{\cal P}}
 \newcommand{\root}[2][]{\,\sqrt[#1]{\vphantom{\large A}\,#2\,}\,}
 \newcommand{\sech}{\,{\rm sech}}
 \newcommand{\sgn}{\,{\rm sgn}}
 \newcommand{\totald}[3][]{\frac{{\rm d}^{#1} #2}{{\rm d} #3^{#1}}}
 \newcommand{\ul}[1]{\underline{#1}}
 \newcommand{\verts}[1]{\left\vert\, #1 \,\right\vert}
 \newcommand{\wt}[1]{\widetilde{#1}}$
\begin{align}&\color{#c00000}{%
\int_{0}^{\infty}{\ln^{2}\pars{x} \over 1 + x^{2}}\,\dd x}
=\int_{0}^{\infty}{\ln^{2}\pars{x^{1/2}} \over 1 + x}\,\half\,x^{-1/2}\dd x
={1 \over 8}\int_{0}^{\infty}{x^{-1/2}\ln^{2}\pars{x} \over x + 1}\,\dd x
\\[3mm]&={1 \over 8}\lim_{\mu \to -1/2}\partiald[2]{}{\mu}
\color{#00f}{\int_{0}^{\infty}{x^{\mu} \over x + 1}\,\dd x}
\end{align}

\begin{align}&\color{#00f}{\int_{0}^{\infty}{x^{\mu} \over x + 1}\,\dd x}
=2\pi\ic\expo{\ic\pi\mu}
-\int_{\infty}^{0}{x^{\mu}\expo{2\pi\mu\ic}\over x + 1}\,\dd x
\quad\imp\quad
\int_{0}^{\infty}{x^{\mu} \over x + 1}\,\dd x
=2\pi\ic\,{\expo{\ic\pi\mu} \over 1 - \expo{2\pi\mu\ic}}
\end{align}

$$
\color{#00f}{\int_{0}^{\infty}{x^{\mu} \over x + 1}\,\dd x}
=-\,{\pi \over \sin\pars{\pi\mu}}
$$

\begin{align}&\color{#44f}{\large%
\int_{0}^{\infty}{\ln^{2}\pars{x} \over 1 + x^{2}}\,\dd x}
={1 \over 8}\lim_{\mu \to -1/2}\partiald[2]{}{\mu}
\bracks{-\,{\pi \over \sin\pars{\pi\mu}}}
\\[3mm]&={1 \over 8}\,\braces{\vphantom{\huge A}-\pi\left[\vphantom{\Large A}\pi^{2}\csc^3\left(\pi\mu\right) +\pi^{2}
\cot^{2}\left(\pi\mu\right)\csc\left(\pi\mu\right)\right]}_{\mu\ =\ -1/2}
=\color{#44f}{\large{1 \over 8}\,\pi^{3}}
\end{align}

A: If $x < 0$, $$\ln (x) = \ln(-|x|) = \ln(e^{i\pi}|x|) = \ln(|x|) + i\pi$$ which is the definition of the complex logarithm for $x < 0$ (for any branch containing $\pi$). 
Having said that, your contour is problematic as it goes through zero where $\ln x$ has a singularity. Instead you should consider a contour like half an annulus: a semicircular arc from $R$ to $-R$, then a straight line segment from $-R$ to $-\varepsilon$, then a semicircular arc from $-\varepsilon$ to $\varepsilon$, then finally a straight line segment from $\varepsilon$ to $R$. As $R \to \infty$ and $\varepsilon \to 0$, the integrals along the semicircular arcs go to zero and then you are left with the calculation in your post.
A: I will give a solution which is a bit short on detail, but hopefully an improvement on your scanned solution which is very short on detail :)
Write
$$I=\int_0^\infty \frac{(\ln x)^2}{1+x^2}\,dx\quad\hbox{and}\quad
  J=\int_C \frac{f(z)^2}{1+z^2}\,dz\ .$$
In the complex integral, $C$ is the contour consisting of the following four parts:


*

*$C_1$: along the $x$ axis from $\rho$ to $R$, where $0<\rho<1<R$;

*$C_2$: the upper semicircle from $R$ to $-R$;

*$C_3$: along the $x$ axis from $-R$ to $-\rho$;

*$C_4$: the upper semicircle from $-\rho$ to $\rho$.


And $f$ is the function defined by
$$f(z)=f(re^{i\theta})=\ln r+i\theta\ ,\quad\hbox{with}\quad
  r>0\ ,\ -\frac{\pi}{2}<\theta<\frac{5\pi}{2}\ .$$
Essentially, $f$ is an "unconventional" branch of the complex logarithm function; it can be shown that $f$ is analytic for all $z$ except when $z=0$ or ${\rm Arg}\,z=-\frac{\pi}{2}$.  In particular, the integrand is analytic on and inside $C$ except for a simple pole at $z=i$, and by residues or CIF you get
$$J=-\frac{\pi^3}{4}\ .$$
Now integrating along $C_1$ gives
$$J_1=\int_\rho^R \frac{(\ln x)^2}{1+x^2}\,dx$$
which tends to $I$ as $\rho\to0^+$ and $R\to\infty$.  Along $C_3$, we have $r=|x|$, $\theta=\pi$, so
$$f(z)=\ln|x|+i\pi$$
and
$$J_3=\int_{-R}^{-\rho} \frac{(\ln|x|+i\pi)^2}{1+x^2}\,dx
  =\int_{\rho}^R \frac{(\ln x+i\pi)^2}{1+x^2}\,dx\ ,$$
where the last integral comes from replacing $x$ by $-x$ in the previous one.  Thus
$$J_3=\int_{\rho}^R \frac{(\ln x)^2+2i\pi\ln x-\pi^2}{1+x^2}\,dx\ .$$
It can also be shown (this is where your solution is really lacking) that the parts of $J$ along $C_2$ and $C_4$ both tend to zero as $\rho\to0^+$ and $R\to\infty$.  Putting all this together and taking the limit,
$$\eqalign{-\frac{\pi^3}{4}
  &=I+I+2i\pi\int_0^\infty \frac{\ln x}{1+x^2}\,dx
    -\pi^2\int_0^\infty \frac{dx}{1+x^2}\cr
  &=2I+2i\pi\int_0^\infty \frac{\ln x}{1+x^2}\,dx
    -\pi^2\Bigl(\frac{\pi}{2}\Bigr)\ .\cr}$$
Taking real parts eliminates the integral in the middle, then you easily solve for $I$.
A minor comment: I have done $J_3$ as above to match your working.  However I would have thought it was slightly easier to say that along $C_3$ we have $z=-x$ where $x$ goes from $R$ to $\rho$, so we have directly
$$J_3=-\int_\rho^R \frac{(\ln x+i\pi)^2}{1+x^2}(-dx)\ .$$
