Using complex method to evaluate $\int_0^\infty\frac{\ln(1+x)}{1+x^2}dx$ Evaluate$$I=\int_0^\infty\frac{\ln(1+x)}{1+x^2}dx$$
I know the answer and other methods to solve this integral. I want to know what is wrong with my attempt.
Let $f(z)=\frac{\ln(1+z)\ln z}{1+z^2}$, where $\Im\ln(1+z)\in(-\pi,\pi]$ and $\Im \ln z\in[0,2\pi)$.
Take the "keyhole contour" $C=C_+\cup C_R\cup C_-\cup C_r$.
Edit: $C_+$: the upside of the positive real axis, $C_-$: the downside of the positive real axis, $C_R$: big circle around the origin, $C_r$: small circle around the origin.
$$\int_Cf(z)dz=2\pi i(\operatorname{Res}_{z=i}f(z)+\operatorname{Res}_{z=-i}f(z))=\frac12\pi^2 i(\ln(1+i)-3\ln(1-i))$$
As $r\to 0$ and $R\to\infty$, $\int_{C_R}f(z)dz$ and $\int_{C_r}f(z)dz$ vanish.
$$(\int_{C_+}+\int_{C_-})f(z)dz=\int_0^\infty\frac{\ln(1+x)}{1+x^2}(\ln x+2\pi i-\ln x)dx$$
Hence I get $$I=\frac{1}{2\pi i}(\int_{C_+}+\int_{C_-})f(z)dz=\frac14\pi(\ln(1+i)-3\ln(1-i))$$
which is wrong.
 A: One problem with the solution in the question is that the difference between $\log(1+z)\log(z)$ above and below the branch cut is not $2\pi i\log(1+z)$ because
$$
(\log(1+z)+2\pi i)(\log(z)+2\pi i)-\log(1+z)\log(z)=2\pi i(\log(1+z)+\log(z))-4\pi^2
$$

Felix Marin gives a contour integration solution in this answer, so I will give a real variable solution here.
$$
\begin{align}
&\int_0^\infty\frac{\log(1+x)}{1+x^2}\,\mathrm{d}x\tag1\\
&=2\int_0^1\frac{\log(1+x)}{1+x^2}\,\mathrm{d}x-\int_0^1\frac{\log(x)}{1+x^2}\,\mathrm{d}x\tag2\\
&=2\int_0^{\pi/4}\log(1+\tan(x))\,\mathrm{d}x-\int_0^1\sum_{k=0}^\infty(-1)^kx^{2k}\log(x)\,\mathrm{d}x\tag3\\
&=2\int_0^{\pi/4}\log(\cos(x)+\sin(x))\,\mathrm{d}x-2\int_0^{\pi/4}\log(\cos(x))\,\mathrm{d}x+\sum_{k=0}^\infty\frac{(-1)^k}{(2k+1)^2}\tag4\\
&=2\int_0^{\pi/4}\log(\sqrt2\cos(\pi/4-x))\,\mathrm{d}x-2\int_0^{\pi/4}\log(\cos(x))\,\mathrm{d}x+G\tag5\\[6pt]
&=\frac\pi4\log(2)+G\tag6
\end{align}
$$
Explanation:
$(2)$: $\int_1^\infty\frac{\log(1+x)}{1+x^2}\,\mathrm{d}x\overset{x\mapsto1/x}=\int_0^1\frac{\log(1+x)-\log(x)}{1+x^2}\,\mathrm{d}x$
$(3)$: substitute $x\mapsto\tan(x)$ on left and use Taylor series on the right
$(4)$: $1+\tan(x)=\frac{\cos(x)+\sin(x)}{\cos(x)}$ and $\int_0^1x^k\log(x)\,\mathrm{d}x=\frac1{(k+1)^2}$
$(5)$: cosine of a difference and definition of Catalan's Constant
$(6)$: cancellation$\vphantom{\sum\limits_{k=0}^\infty}$

Edit: I thought I had answered this before, but I couldn't find my previous answer until I noticed Jyrki's "Also" link. This solution is close, but has a difference in computing $\int_0^1\frac{\log(1+x)}{1+x^2}\,\mathrm{d}x$.
