Complex part of a contour integration not using contour integration

I believe that I misunderstood the question in my first answer. What I think you want is a way to compute $$ \int_0^\infty\frac{\log(x)}{1+x^2}\mathrm{d}x $$ without using complex analysis.

With the substitution $x\mapsto\frac1x$, we get $$ \int_0^\infty\frac{\log(x)}{1+x^2}\mathrm{d}x=-\int_0^\infty\frac{\log(x)}{1+x^2}\mathrm{d}x $$ which says that $$ \int_0^\infty\frac{\log(x)}{1+x^2}\mathrm{d}x=0 $$


A change of variables yields $$ \begin{align} \int_0^\infty\frac{\log(x)^2}{1+x^2}\,\mathrm{d}x &=\int_{-\infty}^\infty\frac{t^2}{1+e^{-2t}}e^-t\,\mathrm{d}t\\ &=2\int_0^\infty\frac{t^2}{1+e^{-2t}}e^{-t}\,\mathrm{d}t\\ &=2\int_{-\infty}^\infty t^2\left(e^{-t}-e^{-3t}+e^{-5t}-e^{-7t}+\dots\right)\,\mathrm{d}t\\ &=4\left(1-\frac{1}{3^3}+\frac{1}{5^3}-\frac{1}{7^3}+\dots\right)\tag{1} \end{align} $$ Define $$ \xi(n)=\sum_{k=0}^\infty(-1)^k\frac{1}{(2k+1)^n}\tag{2} $$ and consider the generating function of $\xi(n)$ for odd $n$: $$ \begin{align} \sum_{n=0}^\infty\sum_{k=0}^\infty(-1)^k\frac{z^{2n+1}}{(2k+1)^{2n+1}} &=\sum_{k=0}^\infty(-1)^k\frac{\frac{z}{2k+1}}{1-\left(\raise{1pt}{\frac{z}{2k+1}}\right)^2}\\ &=\frac{z}{2}\sum_{k=0}^\infty(-1)^k\left(\frac{1}{z+2k+1}-\frac{1}{z-2k-1}\right)\\ &=\frac{z}{2}\sum_{k=-\infty}^\infty\left(\frac{1}{z+4k+1}-\frac{1}{z+4k-1}\right)\\ &=\frac{z}{8}\sum_{k=-\infty}^\infty\left(\frac{1}{k+\frac{z+1}{4}}-\frac{1}{k+\frac{z-1}{4}}\right)\\ &=\frac{z}{8}\left(\pi\cot\left(\pi\frac{z+1}{4}\right)-\pi\cot\left(\pi\frac{z-1}{4}\right)\right)\\ &=\frac{\pi z}{4}\sec\left(\frac{\pi z}{2}\right)\\ &=\frac{\pi z}{4}+\frac{\pi^3z^3}{32}+\frac{5\pi^5z^5}{1536}+\dots\tag{3} \end{align} $$ where we used $(7)$ from this answer.

Putting together $(1)$, $(2)$, and $(3)$ yields $$ \int_0^\infty\frac{\log(x)^2}{1+x^2}\,\mathrm{d}x=\frac{\pi^3}{8}\tag{4} $$


Here is another method using contour integration.

In order to define $\log(z)$, consider the path $\gamma$ that runs from $0$ to $\infty$ just north of the real axis, circles the complex plane counter-clockwise, then returns from $\infty$ to $0$ just south of the real axis.

Adding the residues at $z=i$ and $z=-i$ gives $$ \begin{align} \int_\gamma\frac{\log(z)^3}{1+z^2}\mathrm{d}z &=2\pi i\left(\frac{\left(\frac\pi2i\right)^3}{2i}+\frac{\left(\frac{3\pi}2i\right)^3}{-2i}\right)\\ &=\frac{13\pi^4}{4}i\tag{5} \end{align} $$ Computing the integral along the real axis yields $$ \begin{align} \int_\gamma\frac{\log(z)^3}{1+z^2}\mathrm{d}z &=\int_0^\infty\frac{\log(x)^3-(\log(x)+2\pi i)^3}{1+x^2}\mathrm{d}x\\ &=\int_0^\infty\frac{-3\log(x)^22\pi i+\color{#C00000}{3\log(x)4\pi^2}+\color{#00A000}{8\pi^3i}}{1+x^2}\mathrm{d}x\\ &=-6\pi i\int_0^\infty\frac{\log(x)^2}{1+x^2}\mathrm{d}x+\color{#C00000}{0}+\color{#00A000}{4\pi^4i}\tag{6} \end{align} $$ Equating the real and imaginary parts of $(5)$ and $(6)$ gives $$ \int_0^\infty\frac{\log(x)}{1+x^2}\mathrm{d}x=0\tag{7} $$ and $$ -6\pi i\int_0^\infty\frac{\log(x)^2}{1+x^2}\mathrm{d}x=-\frac{3\pi^4}{4}i\tag{8} $$ which yields $$ \int_0^\infty\frac{\log(x)^2}{1+x^2}\mathrm{d}x=\frac{\pi^3}{8}\tag{9} $$