How to compute $\int_0^\pi \ln^2(\sin x)dx$ using complex analysis? I would like to know if the integral
$$\int_0^\pi \ln^2(\sin x)dx$$
could be attacked with contour integration. I have seen the integral evaluated using the Fourier series for $\ln(\sin x)$ and Cauchy product for infinite sums, but this method gets extremely hard for higher degrees than 2, which is why I want to see it evaluated using complex analysis.
 A: There is a method to evaluate your integral using contour integration, though I'm unsure if it generalises neatly to higher powers. First, let
\begin{equation}
\begin{split}
I&=\int_0^\pi\log^2(\sin(\theta))d\theta\\
&=\frac12 \int_0^{2\pi}\log^2(\sin(\theta /2))d\theta\\
&=\frac12 \int_0^{2\pi}\left[\log(1-e^{i\theta})-\log(2) -\frac{i}{2}(\theta-\pi)\right]^2d\theta\\
\end{split}
\end{equation}
(Note that we're taking the principal branch of the logarithm)
Expanding the square, and taking real parts (which we may do since $I$ is real valued), we see that $I=\frac{1}{2}(J_1+J_2+J_3)$, where
\begin{equation}
\begin{split}
J_1&=\mathfrak{R}\int_0^{2\pi}\left[\log^2(2)-\frac14(\theta-\pi)^2\right]d\theta\\
J_2&=\mathfrak{R}\int_0^{2\pi}[-i\log(1-e^{i\theta})(\theta-\pi)]d\theta\\
J_3&=\mathfrak{R}\int_0^{2\pi}[\log^2(1-e^{i\theta})-2\log(2)\log(1-e^{i\theta})]d\theta\\
\end{split}
\end{equation}
It is easy to evaluate $J_1=2\pi\log^2(2)-\frac{\pi^3}{6}$. To evaluate $J_2$, note that $\mathfrak{R}[-i\log(1-e^{i\theta})]=\frac{1}{2}(\theta-\pi)$ for $\theta\in(0,2\pi)$, so
\begin{equation}
J_2=\int_0^{2\pi}\frac{1}{2}(\theta-\pi)^2d\theta=\frac{\pi^3}{3}
\end{equation}
Finally, to evaluate $J_3$, note that
\begin{equation}
\begin{split}
J_3&=\mathfrak{R}\lim_{r\rightarrow 1^{-}}\int_0^{2\pi}[\log^2(1-re^{i\theta})-2\log(2)\log(1-re^{i\theta})]d\theta\\
&=\mathfrak{R}\lim_{r\rightarrow 1^{-}}\oint_{|z|=r}-\frac{i}{z}[\log^2(1-z)-2\log(2)\log(1-z)]dz\\
\end{split}
\end{equation}
Since the above integrand is analytic in the open unit disc (apart from a removable singularity at $z=0$), by Cauchy's integral theorem, the above integrals vanish for each $r\in(0,1)$, and thus $J_3=0$. Combining our work, we have that
\begin{equation}
I=\pi\log^2(2)+\frac{\pi^3}{12}
\end{equation}
