Two improper log integrals Evaluate
$$\int_0^{\frac{\pi}{2}}\ln ^2(\tan x)\text{d}x$$
$$\int_0^{\frac{\pi}{2}}\ln ^2(\sin x)\text{d}x$$

Per @julien's comment:  Let $u=\tan{x}$ and transform the integral into
$$\int_0^{\infty} du \frac{\log^2{u}}{1+u^2} $$
This can be evaluated via the residue theorem.  Consider the integral
$$\oint_C dz \frac{\log^3{z}}{1+z^2}$$
where $C$ is a keyhole contour about the positive real axis.  The integral about the contour arcs that go to infinity and zero, respectively, go to zero in those limits.  We are left with
$$\begin{align}\oint_C dz \frac{\log^3{z}}{1+z^2} &= \int_0^{\infty} du \frac{\log^3{u}}{1+u^2} - \int_0^{\infty} du \frac{(\log{u}+ i 2 \pi)^3}{1+u^2}\\ &= -i 6 \pi \int_0^{\infty} du \frac{\log^2{u}}{1+u^2} + 12 \pi^2 \int_0^{\infty} du \frac{\log{u}}{1+u^2} + i 8 \pi^3 \int_0^{\infty} du \frac{1}{1+u^2} \end{align}$$
The value of this integral is equal to $i 2 \pi$ times the sum of the residues of the poles of the integrands, which are $e^{i \pi/2}$ and $e^{i 3\pi/2}$.  The residues at these poles are
$$\mathrm{Res}_{z=e^{i \pi/2}} = \frac{-i \pi^3/8}{2 i}$$
$$\mathrm{Res}_{z=e^{i 3\pi/2}} = \frac{-i 27\pi^3/8}{-2 i}$$
We may then write
$$i \left [- 6 \pi \int_0^{\infty} du \frac{\log^2{u}}{1+u^2} + 8 \pi^3 \int_0^{\infty} du \frac{1}{1+u^2} \right ] + 12 \pi^2 \int_0^{\infty} du \frac{\log{u}}{1+u^2} = i \frac{13 \pi^4}{4}$$
Now use the fact that 
$$\int_0^{\infty} du \frac{1}{1+u^2} = \frac{\pi}{2}$$
and equate real and imaginary parts to get
$$\int_0^{\infty} du \frac{\log^2{u}}{1+u^2} = \frac{\pi^3}{8}$$
$$\int_0^{\infty} du \frac{\log{u}}{1+u^2} = 0$$
Therefore, the value of the stated integral is
$$\int_0^{\pi/2} dx \: \log^2{(\tan{x})} = \frac{\pi^3}{8}$$
