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$$
 A: 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}$$
A: For the first integral, making the change of variable $ \tan(x)=y $ yields
$$ \int_0^{\frac{\pi}{2}}\ln ^2(\tan x)\text{d}x = \int_0^{\frac{\pi}{2}}\frac{\ln ^2(x)}{1+x^2}\text{d}x = I. $$
to evaluate the last integral, we consider the integral
$$ \int_0^{\frac{\pi}{2}}\frac{x^s}{1+x^2}\text{d}x = \frac{\pi}{2} \,\sec \left( \frac{\pi\,s}{2} \right) = F(s).   $$
which can be evaluated using $\beta$ function. Here is a related problem. Now, $I$ follows from $F$ as
$$ I = \lim_{s\to 0} \frac{d^2F(s)}{ds^2} = \frac{\pi^3}{8}. $$
For the second integral, you can use the same approach. Here is a related problem. 
A: These integrals can be evaluated by using the following identities;
$$\forall x\in \left(0, \frac{\pi}{2}\right);\phantom{;}\log(\sin x)=-\log 2-\sum_{n\ge 1}\frac{\cos(2nx)}{n} \quad\cdots (1)$$
$$\forall x\in \left(0, \frac{\pi}{2}\right);\phantom{;}\log(\cos x)=-\log 2-\sum_{n\ge 1}\frac{(-1)^n \cos(2nx)}{n} \quad\cdots (2)$$
For example, the second integral can be written like the following;
$$\begin{aligned}A&:=\int_{0}^{\pi/2}\log^2 (\sin x)dx
\\&=\int_{0}^{\pi/2}\left(-\log 2-\sum_{n\ge 1}\frac{\cos(2nx)}{n}\right)^2 dx\phantom{;}(\because (1))
\\&=\frac{\pi}{2}\log^2 2+\sum_{m, n\ge 1}\left(\frac{1}{mn}\int_{0}^{\pi/2}\cos(2nx)\cos(2mx)dx\right)+2\log 2 \sum_{n\ge 1}\left(\frac{1}{n}\int_{0}^{\pi/2}\cos(2nx) dx\right)
\end{aligned}$$
(Note that I interchanged integral and summation in the third line.)
For positive integer $m$ and $n$,
$$\int_{0}^{\pi/2}\cos(2nx)\cos(2mx)dx=\begin{cases}\frac{\pi}{4}\mbox{ (when }m=n\mbox{)}\\0\mbox{ (otherwise)} \end{cases}$$
$$\int_{0}^{\pi/2}\cos(2nx)dx=0$$
So
$$A=\frac{\pi}{2}\log^2 2+\frac{\pi}{4}\sum_{n\ge 1}\frac{1}{n^2}=\color{blue}{\frac{\pi}{2}\log^2 2+\frac{\pi^3}{24}}$$

The first integral can be evaluated similarly; observing that
$$\int_{0}^{\pi/2}\log^2 (\tan x) dx =\int_{0}^{\pi/2}(\log^2 (\sin x)+\log^2 (\cos x)-2\log(\sin x)\log(\cos x)) dx$$
