Evaluating real integral using residue calculus: why different results? I have to evaluate the real integral
$$
I = \int_0^{\infty} \frac{\log^2 x}{x^2+1}.
$$
using residue calculus.
Its value is $\frac{\pi^3}{8}$, as you can verify (for example) introducing the function
$$
  \frac{(\log z-i(\pi/2))^2}{z^2+1}.
$$ and considering the branch cut for the logarithm function on the negative semiaxis of the immaginary numbers and an upper half-circle indented at 0 as integration contour.
I tried a different method, but unfortunately I obtained a different result and I don't know why. I consider the branching axis of the logarithm function as the positive real semiaxis.
I tried as integration contour this closed curve. I used the complex function
$$
f(z)=\frac{\log^3z}{z^2+1}
$$
obtaining 
$$
\int_r^{R} \frac{\log^3 x}{x^2+1}\;dx + \int_\Gamma \frac{\log^3 z}{z^2+1}\;dz - \int_r^{R} \frac{(\log x+2\pi i)^3}{x^2+1}\;dx - \int_\gamma \frac{\log^3 z}{z^2+1}\;dz.
$$
It is easy to see that integrals over circular paths $\gamma$ and $\Gamma$ tend to zero when $R\to \infty,r\to 0$. So we have to evaluate
$$
\int_r^{R} \frac{\log^3 x}{x^2+1}\;dx - \int_r^{R} \frac{(\log x+2\pi i)^3}{x^2+1}\;dx,
$$
which immaginary part is (EDIT: changed $8\pi i$ to $8\pi^3 i$ )
$$
-6\pi i \int_r^{R} \frac{\log^2 x}{x^2+1}\;dx + 8\pi^3 i \int_r^{R} \frac{1}{x^2+1}\;dx,
$$
that has to be equal to the immaginary part of
$$
2\pi i\;\left( \mathrm{Res} \left[f,i \right] + \mathrm{Res}\left[f,-i \right]\right) = -i \frac{\pi^4}{4}.
$$ 
So, doing the rest of the work, finally I found that the result is $\frac{17\pi^3}{24}$, that is clearly different from $\frac{\pi^3}{8}$... but where is the flaw in my argument? Please help
 A: The error is where you get
$$2\pi i\;\left( \mathrm{Res} \left[f,i \right] + \mathrm{Res}\left[f,-i \right]\right) = -i \frac{\pi^4}{4}.$$
If you use $\arg{i}=\frac{\pi}{2}$ then you must have $\arg(-i)=\frac{3\pi}{2}$ instead of $\arg(-i)=-\frac{\pi}{2}$, since you must use the same branch of the logarithm all through.
Taking this into account, we instead get
$$2\pi i\;\left( \mathrm{Res} \left[f,i \right] + \mathrm{Res}\left[f,-i \right]\right) = \frac{13i\pi^4}{4}.$$
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}}$
$\ds{I\equiv\int_{0}^{\infty}{\ln^{2}\pars{x} \over x^{2} + 1}\,\dd x:\
     {\large ?}}$

Let $\quad\ds{\ln\pars{z} = \ln\pars{\verts{z}} + \ic{\rm Arg}\pars{z}.\quad
0 < {\rm Arg}\pars{z} < 2\pi.\quad}$
According to the $\ds{\large\ln}$-branch cut, the integrand has poles at $\quad\ds{\expo{\pi\ic/2}}\quad$ and $\quad\ds{\expo{3\pi\ic/2}}$:

\begin{align}
&\int_{0}^{\infty}{\ln^{3}\pars{x} \over x^{2} + 1}\,\dd x
=2\pi\ic\,{\pars{\pi\ic/2}^{3} \over \ic + \ic}
+2\pi\ic\,{\pars{3\pi\ic/2}^{3} \over -\ic - \ic}
-\int_{\infty}^{0}{\bracks{\ln\pars{x} + 2\pi\ic}^{3} \over x^{2} + 1}\,\dd x
\\[3mm]&=-\,{\pi^{4} \over 8}\,\ic + {27\pi^{4} \over 8}\,\ic
+\int_{0}^{\infty}{\ln^{3}\pars{x} \over x^{2} + 1}\,\dd x
+6\pi\ic\int_{0}^{\infty}{\ln^{2}\pars{x} \over x^{2} + 1}\,\dd x
-12\pi^{2}\
\underbrace{\int_{0}^{\infty}{\ln\pars{x} \over x^{2} + 1}\,\dd x}_{\ds{=\ 0}}
\\[3mm]&\phantom{=\!}-8\pi^{3}\ic\
\underbrace{\int_{0}^{\infty}{\dd x \over x^{2} + 1}}_{\ds{=\ {\pi \over 2}}}
\end{align}

\begin{align}
0&=6\pi\ic\int_{0}^{\infty}{\ln^{2}\pars{x} \over x^{2} + 1}\,\dd x
+\pars{-\,{1 \over 8} + {27 \over 8} - 4}\,\pi^{4}\,\ic
=6\pi\ic\int_{0}^{\infty}{\ln^{2}\pars{x} \over x^{2} + 1}\,\dd x
- {3 \over 4}\,\pi^{4}\,\ic
\end{align}

$$\color{#66f}{\large\int_{0}^{\infty}{\ln^{2}\pars{x} \over x^{2} + 1}\,\dd x}
={3\pi^{4}\ic\,/4 \over 6\pi\ic}
=\color{#66f}{\Large{\pi^{3} \over 8}}
$$
