How to calculate the integral $\int_0^{+\infty}\frac{\ln(\cos^2x)}{1+e^{2x}}dx$ 
Calculate the integral $$\int_0^{+\infty}\frac{\ln(\cos^2x)}{1+e^{2x}}\,dx.$$

I tried
$$\displaystyle\ln(\cos^2x)=\ln\left(\frac{\cos2x+1}{2}\right)=\ln(1+\cos2x)-\ln2.$$
It's easy to get the result of
$$\displaystyle\int_0^{+\infty}\frac{-\ln2}{1+e^{2x}}\,dx=-\ln 2$$
and using $2x=t$  for another part
$$\displaystyle \int_0^{+\infty}\frac{\ln(1+\cos2x)}{1+e^{2x}}\,dx$$
I got $$\int_0^{+\infty}\frac{\ln(\cos^2x)}{1+e^{2x}}\,dx=\frac12\int_0^{+\infty}\frac{\ln(1+\cos t)}{1+e^{t}}\,dt-\ln2.$$
I don't know how to calculate the first integral. Could someone help me? Thanks!
 A: The original integral is
$$I = 2\int_0^{\infty} \frac{\ln(|\cos x|)e^{-2x}}{1 + e^{-2x}}dx$$
Use the following result from Fourier series of Log sine and Log cos,
$$\ln(|\cos x|) = -\sum_{k = 1}^{\infty} (-1)^k\frac{\cos(2kx)}{k} - \ln 2 \, \, \forall x \in \mathbb{R}$$
i.e
$$ I = -2\sum_{k=1}^{\infty}\frac{(-1)^k}{k}\int_0^{\infty}\frac{\cos(2kx)e^{-2x}}{1 + e^{-2x}}dx - 2\ln2\int_0^{\infty}\frac{e^{-2x}}{1 + e^{-2x}}dx$$
The right integral is equal to $\frac{\ln 2}{2}$. For the left integral, use the expansion $\frac{1}{1+e^{-2x}} = \sum_{n=0}^{\infty}(-1)^n e^{-2nx}$ since $e^{-2x} < 1$.
$$ I = -2\sum_{k=1}^{\infty}\sum_{n=0}^{\infty}\frac{(-1)^{k + n}}{k}\int_0^{\infty}\cos(2kx)e^{-2x(n+1)}dx - \ln^2 2$$
Call the integral inside the sum as $J$.
$$J = \int_0^{\infty} \cos(2kx)e^{-2x(n + 1)}dx = \Re\int_0^{\infty} e^{-2x(n + 1 +ik)}dx = \Re\frac{1}{2(n + 1 + ik)}$$
$$\Rightarrow J = \frac{1}{2}\frac{n + 1}{k^2 + (n + 1)^2}$$
Therefore,
$$I = \sum_{k = 1}^{\infty}\sum_{n = 1}^{\infty} \frac{(-1)^{k + n}}{k}\frac{n}{n^2 + k^2} - \ln^2 2$$
Note the change in summation limits. Call the summation as $S$. Note that replacing $k$ with $n$ won't change the result, hence
$$2S = \sum_{k = 1}^{\infty}\sum_{n = 1}^{\infty}\frac{(-1)^{k + n}}{k}\frac{n}{n^2 + k^2} + \sum_{k = 1}^{\infty}\sum_{n = 1}^{\infty}\frac{(-1)^{k + n}}{n}\frac{k}{n^2 + k^2} $$
$$\Rightarrow S = \frac{1}{2}\sum_{k = 1}^{\infty}\sum_{n = 1}^{\infty}\frac{(-1)^{k + n}}{nk} = \frac{1}{2}\left(\sum_{k = 1}^{\infty}\frac{(-1)^k}{k}\right)^2 = \frac{\ln^2 2}{2}$$
Therefore,
$$ I = \frac{\ln^2 2}{2} - \ln^2 2 = -\frac{\ln^2 2}{2}$$
A: Hopefully, it's never too late :)
Just as an option - a short solution via the complex integration.
Using $\cos^2x=\frac{1+\cos2x}{2}$
$$I=\int_0^\infty\frac{\ln(\cos^2x)}{1+e^{2x}}dx =\int_0^\infty\frac{\ln(2+2\cos2x)}{1+e^{2x}}dx-2\ln2\int_0^\infty\frac{dx}{1+e^{2x}}$$
$$=\int_0^\infty\frac{\ln(1+e^{2ix})+\ln(1+e^{-2ix})}{1+e^{2x}}dx-\ln^22$$
$$I=2\Re\int_0^\infty\frac{\ln(1+e^{2ix})}{1+e^{2x}}dx-\ln^22=2\Re\,J-\ln^22\qquad(1)$$
To evaluate $J$ we consider the closed contour in the complex plane:

The integrand does not have poles inside the contour, therefore
$$\oint\frac{\ln(1+e^{2iz})}{1+e^{2z}}dz=0=J+I_R+\int_{i\infty}^0\frac{\ln(1+e^{2ix})}{1+e^{2x}}dx=J+I_R-i\int_0^\infty\frac{\ln(1+e^{-2t})}{1+e^{2it}}dt$$
where $I_R$ is the integral along the quarter-circle (of the radius $R\to\infty$), counter clockwise. The third integral includes integration along the small half-circles around the points $t=\pi i/2+2\pi i k, \,k=0,1,2...$, clockwise (the point $t=\pi i/2$ - as an example - is on the picture).
Integrating the third term by parts,
$$\oint=J+I_R+\frac{1}{2}\ln(1+e^{-2t})\ln(1+e^{-2it})\,\Big|_{t=0}^{t=\infty}+\int_0^\infty\frac{\ln(1+e^{-2it})}{1+e^{-2t}}e^{-2t}dt$$
It is easy to show that $I_R\to0$ at $R\to\infty$ (please, see below)
$$=I_R\,+\,2\Re\,J\,-\,\frac{\ln^22}{2}=0\qquad(2)$$
From (1), (2) follows:
$$2\Re\,J=\frac{\ln^22}{2}\,\,\Rightarrow\,\,\boxed{\,\,I=2\Re\,J-\ln^22=-\frac{\ln^22}{2}\,\,}$$

Evaluation of $I_R$:
$$|I_R|=\bigg|\int_0^{\pi/2}\frac{\ln\Big(1+e^{2iRe^{i\phi}}\Big)}{1+e^{2Re^{i\phi}}}iRe^{i\phi}d\phi\bigg|<\int_0^{\pi/2}e^{-2R\cos\phi}\ln\big(1+e^{-2R\sin\phi}\big)Rd\phi$$
Making the change of the variable $\,\phi\to\frac{\pi}{2}-\phi\,$, using $\,\sin \phi>\frac{2}{\pi}\,\phi\,$ for $\,\phi\in[0;\pi/2]$, and introducing some fixed $\,\,a ,\,\,0<a<\frac{\pi}{2}$
$$|I_R|<\int_0^ae^{-\frac{4R}{\pi}\phi}\ln\big(1+e^{-2Ra}\big)Rd\phi+\ln2\int_a^{\pi/2}e^{-\frac{4R}{\pi }}Rd\phi=Ra\ln\big(1+e^{-2Ra}\big)+\frac{\pi \ln2}{4}\Big(e^{-\frac{4Ra}{\pi}}-e^{-2R}\Big)\to0\,\,\text{at}\,\,R\to\infty\quad(3)$$
