Integral $\int_0^{\infty} \frac{\ln \cos^2 x}{x^2}dx=-\pi$

Let the desired integral be denoted by $I$. Note that $$\eqalign{ 2I&=\int_{-\infty}^\infty\frac{\ln(\cos^2x)}{x^2}dx= \sum_{n=-\infty}^{+\infty}\left(\int_{n\pi}^{(n+1)\pi}\frac{\ln(\cos^2x)}{x^2}dx\right)\cr &=\sum_{n=-\infty}^{+\infty}\left(\int_{0}^{\pi}\frac{\ln(\cos^2x)}{(x+n\pi)^2}dx\right) \cr &=\int_{0}^{\pi}\left(\sum_{n=-\infty}^{+\infty} \frac{1}{(x+n\pi)^2}\right)\ln(\cos^2x)dx \cr &=\int_{0}^{\pi}\frac{\ln(\cos^2x)}{\sin^2x}dx \cr } $$ where the interchange of the signs of integration and summation is justified by the fact that the integrands are all negative, and we used the well-known expansion: $$ \sum_{n=-\infty}^{+\infty} \frac{1}{(x+n\pi)^2}=\frac{1}{\sin^2x}.\tag{1} $$ Now using the symmetry of the integrand arround the line $x=\pi/2$, we conclude that $$\eqalign{ I&=\int_{0}^{\pi/2}\frac{\ln(\cos^2x)}{\sin^2x}dx\cr &=\Big[-\cot(x)\ln(\cos^2x)\Big]_{0}^{\pi/2}+\int_0^{\pi/2}\cot(x)\frac{-2\cos x\sin x}{\cos^2x}dx\cr &=0-2\int_0^{\pi/2}dx=-\pi. } $$ and the announced conclusion follows.$\qquad\square$

Remark: Here is a proof of $(1)$ that does not use residue theorem. Consider $\alpha\in(0,1)$, and let $f_\alpha$ be the $2\pi$-periodic function that coincides with $x\mapsto e^{i\alpha x}$ on the interval $(-\pi,\pi)$. It is easy to check that the exponential Fourier coefficients of $f_\alpha$ are given by $$ C_n(f_\alpha)=\frac{1}{2\pi}\int_{-\pi}^{\pi}f_\alpha(x)e^{-inx}dx=\sin(\alpha\pi)\frac{(-1)^n}{\alpha \pi-n\pi} $$ So, by Parseval's formula we have $$ \sum_{n\in\Bbb{Z}}\vert C_n(f_\alpha)\vert^2=\frac{1}{2\pi}\int_{-\pi}^\pi\vert f_\alpha(x)\vert^2dx $$ That is $$ \sin^2(\pi\alpha) \sum_{n\in\Bbb{Z}}\frac{1}{(\alpha\pi-n\pi)^2}=1 $$ and we get $(1)$ by setting $x=\alpha\pi\in(0,\pi)$.