Say we want to evaluate $\int^\infty_0 \frac{(\log(x))^2}{x^2+1}\,dx $ via integrating over a complex contour.
My lecturer said to use the function $f(z) = \frac{(\log(z) - \frac{i \pi}{2})^2}{z^2+1}\ $ with the branch cut along the negative imaginary axis over the following contour:
I understand the contour choice: we include the $i$ pole to take the residue of, and we avoid the branch cut. However, I don't understand the intuition behind why they've change the function from $\log(z)$ to $\log(z) - \frac{i \pi}{2}$. Why is that of benefit to us?

Note that with the branch cut along the negative real axis, we see that along the positive real axis
$$(\log(z)-i\pi/2)^2=\log^2(|x|)-i\pi\log(|x|)-\pi^2/4$$
while along the negative real axis
$$(\log(z)-i\pi/2)^2=\log^2(|x|)+i\pi\log(|x|)-\pi^2/4$$
It is easy to show that $\int_{-\infty}^0 \frac{\log^2(|x|)}{1+x^2}\,dx=\int_0^{\infty} \frac{\log^2(|x|)}{1+x^2}\,dx$.
Hence, $\int_{-\infty}^\infty \frac{(\log(x)-i\pi/2)^2}{x^2+1}\,dx=2\int_0^\infty \frac{\log^2(x)}{x^2+1}\,dx-\frac12 \pi^2\int_0^\infty \frac{1}{x^2+1}\,dx$. So, the cross term involving $\log(x)$ is no involved.
Therefore, we have
$$\begin{align} \oint_C \frac{(\log(z)-i\pi/2)^2}{z^2+1}\,dz&=2\int_\epsilon^R \frac{\log^2(x)}{x^2+1}\,dx-\frac12\pi^2\underbrace{\int_\epsilon^R \frac{1}{x^2+1}\,dx}_{\to -\pi^3/4\,\text{as}\,\epsilon\to 0\,\text{and}\,R\to\infty}\\\\ &+\underbrace{\int_\pi^0 \frac{\log^2(\epsilon e^{i\phi})}{(\epsilon e^{i\phi})^2+1}\,i\epsilon e^{i\phi}\,d\phi}_{\to 0\,\text{as}\,\epsilon\to 0}+\underbrace{\int_0^\pi \frac{\log^2(R e^{i\phi})}{(R e^{i\phi})^2+1}\,i R e^{i\phi}\,d\phi}_{\to 0\,\text{as}\,R\to \infty}\\\\ &=2\pi i \text{Res}\left(\frac{(\log(z)-i\pi/2)^2}{z^2+1}, z=i\right)\\\\ &=0 \end{align}$$
Therefore, as $\epsilon\to 0$ and $R\to \infty$ we see that
$$\int_0^\infty \frac{\log^2(x)}{x^2+1}\,dx=\frac{\pi^3}{8}$$