Definite Integral involving logarithm and tangent function 
Show that
$$\mathcal{I}:=\int_0^{\frac{\pi}2} \log |1-a^2\tan^2\theta| d\theta= \pi\log\sqrt{a^2+1}.$$

I tried to use the substitution $\tan\theta=z$, to get that
$$\mathcal{I}:=\int_0^{\infty} \frac{\log|1-a^2z^2|}{z^2+1}dz$$
This integral is quite similar to this one:
Evaluating $\int_0^{\infty}\frac{\ln(x^2+1)}{x^2+1}dx$
However note that the sign inside the logarithm term is different and it seems none of the idea is applicable to this setting. May be there is a way to use the above link result to prove my integral. But I dont know.
Edit: Okay I think I have figured out one way to do it via contour integration. We can take a contour that looks like a large semicircle on the upper half plane so that it encloses only the pole at $z=i$. The contour should also have two holes around $z=\pm \frac1a$ to avoid the singularity coming from $\log$. Then Residue Calculus gives the desired result.
It would be nice to see a proof without residue calculus as well.

$\newcommand{\bbx}[1]{\,\bbox[15px,border:1px groove navy]{\displaystyle{#1}}\,}
 \newcommand{\braces}[1]{\left\lbrace\,{#1}\,\right\rbrace}
 \newcommand{\bracks}[1]{\left\lbrack\,{#1}\,\right\rbrack}
 \newcommand{\dd}{\mathrm{d}}
 \newcommand{\ds}[1]{\displaystyle{#1}}
 \newcommand{\expo}[1]{\,\mathrm{e}^{#1}\,}
 \newcommand{\ic}{\mathrm{i}}
 \newcommand{\mc}[1]{\mathcal{#1}}
 \newcommand{\mrm}[1]{\mathrm{#1}}
 \newcommand{\pars}[1]{\left(\,{#1}\,\right)}
 \newcommand{\partiald}[3][]{\frac{\partial^{#1} #2}{\partial #3^{#1}}}
 \newcommand{\root}[2][]{\,\sqrt[#1]{\,{#2}\,}\,}
 \newcommand{\totald}[3][]{\frac{\mathrm{d}^{#1} #2}{\mathrm{d} #3^{#1}}}
 \newcommand{\verts}[1]{\left\vert\,{#1}\,\right\vert}$
Lets $\ds{\mathcal{I}\pars{\beta} \equiv \int_{0}^{\pi/2}\ln\pars{\verts{1 - \beta\tan\pars{\theta}}}\,\dd\theta}$ such that
$$
\underbrace{\bbox[5px,#ffd]{\int_{0}^{\pi/2}\ln\pars{\verts{1 - a^{2}\tan\pars{\theta}}}\,\dd\theta}}
_{\ds{\vphantom{\LARGE A}\Large ?}}\ =\
\mathcal{I}\pars{a} + \mathcal{I}\pars{-a}
$$

\begin{align}
\mathcal{I}'\pars{\beta} &\equiv \int_{0}^{\pi/2}
{-\tan\pars{\theta}\over 1 - \beta\tan\pars{\theta}}\,\dd\theta =
-\int_{0}^{\pi/2}
{\sin\pars{\theta}\over \cos\pars{\theta} - \beta\sin\pars{\theta}}\,\dd\theta
\\[5mm] & =
\left.-\int_{0}^{\pi/2}
{\sin\pars{\theta}\over \cos\pars{\theta} - \tan\pars{\phi}\sin\pars{\theta}}\,\dd\theta
\,\right\vert_{\large\ \color{red}{\phi\ \equiv\ \arctan\pars{\beta}}}
\\[5mm] = &\
-\cos\pars{\phi}\int_{0}^{\pi/2}
{\sin\pars{\theta}\over \cos\pars{\theta + \phi}}\,\dd\theta
\\[5mm] & =
-\cos\pars{\phi}\int_{\phi}^{\pi/2 + \phi}
{\sin\pars{\theta - \phi}\over \cos\pars{\theta}}\,\dd\theta
\\[5mm] & =
-\cos^{2}\pars{\phi}\int_{\phi}^{\pi/2 + \phi}\tan\pars{\theta}\dd\theta
+ {\pi \over 2}\sin\pars{\phi}\cos\pars{\phi}
\\[5mm] & =
{1 \over \tan^{2}\pars{\phi} + 1}
\ln\pars{\verts{\cos\pars{\phi + \pi/2}} \over \verts{\cos\pars{\phi}}} + {\pi \over 2}
{\tan\pars{\phi} \over \tan^{2}\pars{\phi} + 1}
\\[5mm] & =
{\ln\pars{\verts{\beta}} + \pi\beta/2 \over \beta^{2} + 1}
\end{align}

Then
$\ds{\pars{~\mbox{with}\ \mathcal{I}\pars{0} = 0~}}$,
\begin{align}
&\bbox[5px,#ffd]{\int_{0}^{\pi/2}\ln\pars{\verts{1 - a^{2}\tan\pars{\theta}}}\,\dd\theta}
\\[5mm] = &\
\int_{0}^{a}{\ln\pars{\verts{\beta}} + \pi\beta/2 \over \beta^{2} + 1}\,\dd\beta +
\int_{0}^{-a}{\ln\pars{\verts{\beta}} + \pi\beta/2 \over \beta^{2} + 1}\,\dd\beta
\\[5mm] = &\
\pi\int_{0}^{a}{\beta \over \beta^{2} + 1}\,\dd\beta =
\pi\,{1 \over 2}\ln\pars{a^{2} + 1} =
\bbx{\pi\ln\pars{\root{a^{2} + 1}}} \\ &
\end{align}
