Evaluating $\int _0^{\frac{\pi }{2}}x\cot \left(x\right)\ln ^2\left(\cos \left(x\right)\right)\:dx$ I want to evaluate $\displaystyle \int _0^{\frac{\pi }{2}}x\cot \left(x\right)\ln ^2\left(\cos \left(x\right)\right)\:dx$ but it's quite difficult.
I have tried to rewrite the integral as
$$\int _0^{\frac{\pi }{2}}x\cot \left(x\right)\ln ^2\left(\cos \left(x\right)\right)\:dx=\frac{\pi }{2}\int _0^{\frac{\pi }{2}}\tan \left(x\right)\ln ^2\left(\sin \left(x\right)\right)\:dx-\int _0^{\frac{\pi }{2}}x\tan \left(x\right)\ln ^2\left(\sin \left(x\right)\right)\:dx$$
I've also tried to integrate by parts in multiple ways yet I cant go forth with this integral, I also tried using the substitution $t=\tan{\frac{x}{2}}$ but cant get anything to work, I'll appreciate any sort of help.
I also tried using the classical expansion
$$\ln \left(\cos \left(x\right)\right)=-\ln \left(2\right)-\sum _{n=1}^{\infty }\frac{\left(-1\right)^n\cos \left(2nx\right)}{n},\:-\frac{\pi }{2}<x<\frac{\pi }{2}$$
But it only gets worse.
 A: $$I=\frac{1}{2}\int_0^{\pi/2} x^2\frac{\ln^2\cos x}{\sin^2x} \, dx+\int_0^{\pi/2} x^2{\ln\cos x}\,dx$$ integrating by parts
$$\int_0^{\pi/2} x^2 \ln\cos x \, dx=\frac{\pi^3}{24}\ln2-\frac{\pi}{4}\zeta(3)$$ see Integral $\int_0^\pi \theta^2 \ln^2\big(2\cos\frac{\theta}{2}\big)d \theta$.
$$I=\int_0^{\pi/2} x^2\frac{\ln^2\cos x}{\sin^2x} \, dx = \frac{1}{4} \int_0^\infty\frac{(\arctan u)^2 \log^2(1+u^2)}{u^2} \, du$$  Put $$x=\arctan u$$
Closer form for $\int_0^\infty\frac{(\arctan{x})^2\log^2({1+x^2})}{x^2}dx$
A: My approach.
$$\int _0^{\frac{\pi }{2}}x\cot \left(x\right)\ln ^2\left(\cos \left(x\right)\right)\:dx$$
$$=\frac{1}{4}\int _0^{\infty }\frac{\arctan \left(x\right)\ln ^2\left(1+x^2\right)}{x\left(1+x^2\right)}\:dx=\frac{\pi }{8}\int _0^{\infty }\frac{\ln ^2\left(1+x^2\right)}{x\left(1+x^2\right)}\:dx$$
$$-\frac{1}{4}\int _0^{\infty }\frac{\arctan \left(\frac{1}{x}\right)\ln ^2\left(1+x^2\right)}{x\left(1+x^2\right)}\:dx$$

$$\int _0^{\infty }\frac{\arctan \left(\frac{1}{x}\right)\ln ^2\left(1+x^2\right)}{x\left(1+x^2\right)}\:dx=\frac{\pi }{2}\int _0^{\infty }\frac{x\ln ^2\left(\frac{x^2}{1+x^2}\right)}{1+x^2}\:dx-\int _0^{\infty }\frac{x\arctan \left(\frac{1}{x}\right)\ln ^2\left(\frac{x^2}{1+x^2}\right)}{1+x^2}\:dx$$
$$=\frac{\pi }{2}\int _0^{\infty }\frac{x\ln ^2\left(\frac{x^2}{1+x^2}\right)}{1+x^2}\:dx-\frac{4}{3}\int _0^{\infty }\frac{x\arctan ^3\left(\frac{1}{x}\right)}{1+x^2}\:dx-\frac{4}{3}\operatorname{\mathfrak{I}} \left\{\int _0^{\infty }\frac{x\ln ^3\left(\frac{x}{x-i}\right)}{1+x^2}\:dx\right\}$$
$$=\frac{\pi }{4}\int _0^1\frac{\ln ^2\left(x\right)}{1-x}\:dx+4\int _0^{\frac{\pi }{2}}x^2\ln \left(\sin \left(x\right)\right)\:dx-\frac{4}{3}\operatorname{\mathfrak{I}} \left\{3\operatorname{Li}_4\left(2\right)+i\pi \ln ^3\left(2\right)-6\zeta \left(4\right)\right\}$$
$$=\frac{5\pi }{4}\zeta \left(3\right)-\frac{\pi ^3}{6}\ln \left(2\right)-\frac{2\pi }{3}\ln ^3\left(2\right)$$

Thus.
$$\frac{1}{4}\int _0^{\infty }\frac{\arctan \left(x\right)\ln ^2\left(1+x^2\right)}{x\left(1+x^2\right)}\:dx=\frac{\pi }{8}\zeta \left(3\right)-\frac{1}{4}\left(\frac{5\pi }{4}\zeta \left(3\right)-\frac{\pi ^3}{6}\ln \left(2\right)-\frac{2\pi }{3}\ln ^3\left(2\right)\right)$$
Therefore.
$$\int _0^{\frac{\pi }{2}}x\cot \left(x\right)\ln ^2\left(\cos \left(x\right)\right)\:dx=-\frac{3\pi }{16}\zeta \left(3\right)+\frac{\pi ^3}{24}\ln \left(2\right)+\frac{\pi }{6}\ln ^3\left(2\right)$$
A: This is not an answer, Cornel's solution mentioned in comment is already quite elegant. Instead I provide some remarks.

Generalizations:
$$\int_0^{\pi/2} x^3 \cot x \log^2(\cos x) \,dx = -3 \pi  \operatorname{Li}_5\left(\frac{1}{2}\right)-3 \pi  \operatorname{Li}_4\left(\frac{1}{2}\right) \log (2)-\frac{3 \pi^3 \zeta (3)}{32}+\frac{141 \pi  \zeta (5)}{64}-\frac{9}{16} \pi  \zeta (3) \log^2(2)-\frac{1}{10} \pi  \log^5(2)+\frac{1}{8} \pi^3 \log^3(2)+\frac{11}{480} \pi^5 \log (2) $$
$$\int_0^{\pi/2} x \cot x \log^4(\cos x) \, dx = -6 \pi  \operatorname{Li}_5\left(\frac{1}{2}\right)-6 \pi  \operatorname{Li}_4\left(\frac{1}{2}\right) \log (2)-\frac{3 \pi ^3 \zeta (3)}{32}+\frac{237 \pi \zeta (5)}{64}-\frac{9}{8} \pi  \zeta (3) \log^2(2)-\frac{1}{10} \pi  \log^5(2)+\frac{1}{4} \pi ^3 \log^3(2)+\frac{19}{480} \pi^5 \log (2)$$
similar evaluations also exist for $\int_0^{\pi/2} x^a \cot x \log^b(\cos x) \log^c(\sin x) \, dx$ with $a$ odd, $b,c$ positive integers  with $a+b+c = 5$.
In OP's question, as well as two examples above, we observe that the results are all "divisible by $\pi$" (each term is multiplied by $\pi$). More generally, when $a$ is odd, $$\int_0^{\pi/2} x^a \cot x \log^b(\cos x) \log^c(\sin x) \, dx = \pi \times (\text{Some alternating Euler sums of weight }a+b+c)$$
When $a$ is even, then $\pi$-factor no longer appears, for example $$\int_0^{\pi /2} x^2 \cot x\ln (\cos x) \, \mathrm{d}x =  - \frac{\pi^4}{720} + \frac{\ln^42}{24} - \frac{\pi^2\ln^22}{6} + \operatorname{Li}_4\left(\frac{1}{2}\right)$$
A: A quite elegant solution.
The fact
$$
\Im\left[\log^3\left(\frac{1+e^{2ix}}2\right)\right]=3x\log^2\cos x-x^3
$$
yields
$$
\int_0^{\pi/2}x\cot x\log^2\cos x~d x=\frac16\Im\left[\int_{-\pi/2}^{\pi/2}\cot x\log^3\left(\frac{1+\text e^{2ix}}2\right)d x\right]+\frac13\int_0^{\pi/2}x^3\cot x~d x
$$
The rest two integrals are easy.
$$
\begin{align}
&\int_{-\pi/2}^{\pi/2}\cot x\log^3\left(\frac{1+\text e^{2ix}}2\right)~d x
\\=&\oint\frac{z+1}{z-1}\log^3\left(\frac{1+z}2\right)~\frac{d z}{2iz}\quad z=e^{2ix}
\\=&2\pi~\text{Res}\left[\frac{z+1}{z-1}\log^3\left(\frac{1+z}2\right)~\frac{1}{2iz},0\right]
\\=&i\pi\log^32
\end{align}
$$
The contour is the unit circle with small perturbations near $z=\pm1$ .
$$
\begin{align}
&\int_0^{\pi/2}x^3\cot x~d x
\\=&x^3\log(2\sin x)\Big|_0^{\pi/2}-3\int_0^{\pi/2}x^2\log(2\sin x)d x
\\=&\frac{\pi^3}8\log2+3\int_0^{\pi/2}\sum_{n\ge1}\frac{\cos(2nx)}nx^2~d x
\\=&\frac{\pi^3}8\log2+3\sum_{n\ge1}\frac{\pi(-1)^n}{4n^3}
\\=&\frac{\pi^3}8\log2-\frac{9\pi}{16}\zeta (3)
\end{align}
$$
Where Fourier series of $\log(2\sin x)$ is applied.
Combine them and the result follows.
$$
\int_0^{\pi/2}x\cot x\log^2\cos x~d x=\frac{\pi^3}{24}\log2-\frac{3\pi}{16}\zeta (3)+\frac\pi6\log^32
$$
