Integral $\int_0^{\infty} \frac{\ln \cos^2 x}{x^2}dx=-\pi$ $$
I:=\int_0^{\infty} \frac{\ln \cos^2 x}{x^2}\text{d}x=-\pi.
$$
Using $2\cos^2 x=1+\cos 2x$ failed me because I ran into two divergent integrals after using $\ln(ab)=\ln a + \ln b$ since I obtained $\int_0^\infty x^{-2}\text{d}x$ and $\int_0^\infty (1+\cos^2 x)\text{d}x $ which both diverge.  Perhaps we should try a complex analysis approach?  I also tried writing
$$
I(\alpha)=\int_0^\infty \frac{\ln \cos^2 \alpha \,x}{x^2}\text{d}x
$$
and obtained
$$
-\frac{dI(\alpha)}{d\alpha}=2\int_0^\infty \frac{\tan \alpha x}{x}\text{d}x=\int_{-\infty}^\infty\frac{\tan \alpha x}{x}\text{d}x.
$$
Taking a second derivative
$$
I''(\alpha)=\int_{-\infty}^\infty {\sec^2 (\alpha x)}\, \text{d}x
$$
Random Variable pointed out how to continue from the integral after the 1st derivative, but is it possible to work with this integral $\sec^2 \alpha x$?  Thanks
 A: There is a wonderful solution:
By Lobachevsky Integral Formula:If f(x) meet $$f(x\pm\pi)=f(x)$$
then $$\int_0^\infty f(x)\cdot\Big(\frac{\sin x}{x}\Big)^2dx=\int_0^\frac{\pi}{2}f(x)dx$$
So back to this problem.
$$I=\int_0^\infty\frac{\ln^2\cos x}{x^2}dx=\int_0^\infty\frac{\ln^2\cos x}{\sin^2x}\cdot\Big(\frac{\sin x}{x}\Big)^2dx=\int_0^\frac{\pi}{2}\frac{\ln^2\cos x}{\sin^2x}dx$$
$$=2\int_0^\frac{\pi}{2}\ln\cos xd\cot x=2\Big(\cot x\ln\cos x\Big|_0^\frac{\pi}{2}-\int_0^\frac{\pi}{2}\cot x\cdot\tan xdx\Big)$$
Notice $$\lim_{x\to\frac{\pi}{2}}\cot x\ln\cos x=\lim_{x\to\frac{\pi}{2}}\frac{\cos x\ln\cos x}{\sin x}=0$$
and
$$\lim_{x\to0}\cot x\ln\cos x=\lim_{x\to0}\frac{\cos x\ln(1-2\sin^2\frac{x}{2})}{\sin x}=\lim_{x\to0}\frac{\cos x(-2\sin^2\frac{x}{2})}{x}=0$$
so $$I=-2\int_0^\frac{\pi}{2}\cot x\cdot \tan xdx=-2\int_0^\frac{\pi}{2}dx=-\pi$$
A: 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)$.
A: Complete the steps for the method attempted in the original problem.
$$I(\alpha)=\int_0^\infty \frac{\ln(\cos^2(\alpha x))}{x^2} dx$$
$$\frac{d}{d\alpha}I(\alpha)=-2\int_0^\infty \frac{\tan(\alpha x)}{x}dx$$
Subsitution: $t=\alpha x$
$$\frac{d}{d\alpha}I(\alpha)=-2\int_{0}^\infty \frac{\tan(t)}{t}dt=-\int_{-\infty}^\infty \frac{\tan(t)}{t}dt=-\sum_{n=-\infty}^\infty \int_{-\frac{\pi}{2}+n\pi}^{\frac{\pi}{2}+n\pi} \frac{\tan(t)}{t}dt$$
Substitution: $z=t-n\pi$ and note that, $\tan(z+n\pi)=\tan(z)$
$$\frac{d}{d\alpha}I(\alpha)=-\sum_{n=-\infty}^\infty \int_{-\frac{\pi}{2}}^{\frac{\pi}{2}} \frac{\tan(z)}{n\pi+z}dz=-\int_{-\frac{\pi}{2}}^{\frac{\pi}{2}} \sum_{n=-\infty}^\infty \frac{\tan(z)}{n\pi+z}dz=-\int_{-\frac{\pi}{2}}^{\frac{\pi}{2}} \tan(z)\sum_{n=-\infty}^\infty \frac{1}{n\pi+z}dz$$
Note,
$$\sum_{n=-\infty}^\infty \frac{1}{n\pi+z}=\cot(z)$$
So we have,
$$\frac{d}{d\alpha}I(\alpha)=-\int_{-\frac{\pi}{2}}^{\frac{\pi}{2}} \tan(z)\cot(z)dz=-\int_{-\frac{\pi}{2}}^{\frac{\pi}{2}} 1dz=-\pi$$
Integrate on $\alpha$, and use initial condition, $I(0)=0$
$$I(\alpha)=-\pi\alpha+C, ~~~C=0$$
Final answer:
$$\int_0^\infty \frac{\ln(\cos^2(x))}{x^2} dx=I(1)=-\pi$$
