Improper integral with log and absolute value: $\int^{\infty}_{0} \frac{\log |\tan x|}{1+x^{2}} \, dx$

How do you show that $$ \int^{\infty}_{0} \frac{\log |\tan x|}{1+x^{2}} \, dx = \frac{\pi}{2} \log (\tanh 1)\, ?$$

I know that the integral converges since $\log |\tan x| = \frac{1}{2} \log(\tan^{2}x)$, and $\log (\tan^{2} x)$ behaves like $2 (-1)^{n} \log \left(x-\frac{n \pi}{2} \right)$ near $x= \frac{n \pi}{2}$. Thus the singularities at $x= \frac{n \pi}{2}$ are integrable.


How about: $$ \int_0^\infty \frac{\log | \tan x |}{1+x^2} \mathrm{d} x = \frac{1}{2} \int_0^\infty \frac{\log \tan^2 x }{1+x^2} \mathrm{d} x = \frac{1}{4} \int_{-\infty}^\infty \frac{\log \tan^2 x }{1+x^2} \mathrm{d} x \tag{$\ast$} $$ Writing the integral over $\mathbb{R}$ as the average of integrals over $\mathbb{R} + i \epsilon$ and $\mathbb{R} - i \epsilon$ and using $\vert \tan(z) \vert^2 = \frac{\sin^2(2 x) + \sinh^2(2y)}{(\cos(2x) + \cosh(2y))^2} \to_{y \to \pm \infty} 1$ we can complete the integration contours and apply the residue theorem: $$ \begin{eqnarray} \int_{-\infty}^\infty \frac{\log \tan^2 x }{1+x^2} \mathrm{d} x &=& \frac{1}{2} \int_{-\infty +i 0}^{\infty +i 0} \frac{\log \tan^2 x }{1+x^2} \mathrm{d} x + \frac{1}{2} \int_{-\infty-i 0}^{\infty - i 0} \frac{\log \tan^2 x }{1+x^2} \mathrm{d} x \\ &=& \frac{1}{2} \cdot 2 \pi i \operatorname{Res}_{x=i}\frac{\log \tan^2 x }{1+x^2} - \frac{1}{2} \cdot 2 \pi i \operatorname{Res}_{x=-i}\frac{\log \tan^2 x }{1+x^2} \\ &=& 2 \pi \log \tanh(1) \end{eqnarray} $$ Combining with eq. $(\ast)$: $$ \int_0^\infty \frac{\log | \tan x |}{1+x^2} \mathrm{d} x = \frac{\pi}{2} \log \tanh(1) $$


Denote the evaluated integral as $I$, then $I$ may be rewritten as $$I=\frac{1}{2}\int_0^\infty \frac{\ln \sin^2 x}{1+x^2}\,dx-\frac{1}{2}\int_0^\infty \frac{\ln \cos^2 x}{1+x^2}\,dx$$ Using Fourier series representations of $\ln \sin^2 \theta$ and $\ln \cos^2 \theta$, $$\ln \sin^2 \theta=-2\ln2-2\sum_{k=1}^\infty \frac{\cos2k\theta}{k}$$ and $$\ln \cos^2 \theta=-2\ln2+2\sum_{k=1}^\infty (-1)^{k+1}\frac{\cos2k\theta}{k}$$ also note that $$\int_0^\infty\frac{\cos ax}{1+x^2}\,dx=\frac{\pi e^{-a}}{2}$$ then $$\begin{align}I&=-\sum_{k=1}^\infty \frac{1}{k}\int_0^\infty\frac{\cos2kx}{1+x^2}\,dx-\sum_{k=1}^\infty \frac{(-1)^{k+1}}{k}\int_0^\infty\frac{\cos2kx}{1+x^2}\,dx\\&=-\pi\sum_{k=1}^\infty \frac{e^{-2k}}{2k}-\pi\sum_{k=1}^\infty (-1)^{k+1}\frac{e^{-2k}}{2k}\\&=\frac{\pi}{2}\ln\left(1-e^{-2}\right)-\frac{\pi}{2}\ln\left(1+e^{-2}\right)\\&=\frac{\pi}{2}\ln\left(\frac{1-e^{-2}}{1+e^{-2}}\right)\\&=\frac{\pi}{2}\ln\left(\tanh 1\right)\end{align}$$