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.
 A: Note that we'll need to take the Cauchy Principal Value. Observe that by DUTIS,
\begin{align*}
    I(a) &= \int_0^{\frac{\pi}{2}} \ln\left|1-a^2\tan^2\theta\right|\,\mathrm{d}\theta\\
    I'(a) &= \int_0^{\frac{\pi}{2}} \frac{\partial}{\partial a} \ln\left|1-a^2\tan^2\theta\right|\,\mathrm{d}\theta\\
    &= \int_0^{\frac{\pi}{2}} \frac{2a \tan^2\theta}{a^2\tan^2\theta-1}\,\mathrm{d}\theta\\
    &= \frac{2}{a} \int_0^{\frac{\pi}{2}} 1 + \frac{1}{a^2 \tan^2\theta - 1} \,\mathrm{d}\theta\\\\
    &= \frac{2}{a} \left ( \lim_{\varepsilon\to 0} \int_0^{\cot^{-1} a - \varepsilon} 1 + \frac{1}{a^2 \tan^2\theta - 1} \, \mathrm{d}\theta + \int_{\cot^{-1} a + \varepsilon}^{\frac{\pi}{2}} 1 + \frac{1}{a^2 \tan^2\theta - 1} \, \mathrm{d}\theta \right ).\\
\end{align*}
so it is sufficient to evaluate the integral of $\dfrac{1}{a^2 \tan^2\theta - 1}$. We have
\begin{align*}
    \int \frac{1}{a^2 \tan^2\theta - 1} \, \mathrm{d}\theta &= \int \frac{1}{(u^2 + 1)(a^2 u^2 - 1)} \, \mathrm{d}u && \text{using $u = \tan\theta$}\\
    &= -\frac{1}{a^2 + 1} \int \frac{1}{u^2 + 1} \, \mathrm{d}u - \frac{a^2}{2(a^2 + 1)} \int \frac{1}{au+1} \, \mathrm{d}u + \frac{a^2}{2(a^2+1)} \int\frac{1}{au-1} \, \mathrm{d}u\\ 
    &= -\frac{\tan^{-1}(u)}{a^2 + 1} - \frac{a \ln |au + 1|}{2(a^2+1)} + \frac{a \ln |au - 1|}{2(a^2+1)} + C\\
    &= \frac{a \ln \left | \frac{a \tan\theta - 1}{a \tan\theta + 1} \right | - 2\theta}{2(a^2 + 1)} + C.
\end{align*}
Applying this to our original equation, we have
\begin{align*}
I'(a) &= \frac{2}{a} \left ( \lim_{\varepsilon\to 0} \left [\theta - \frac{a \ln \left | \frac{a \tan\theta - 1}{a \tan\theta + 1} \right | - 2\theta}{2(a^2 + 1)} \right ]_0^{\cot^{-1} a - \varepsilon} + \left [\theta - \frac{a \ln \left | \frac{a \tan\theta - 1}{a \tan\theta + 1} \right | - 2\theta}{2(a^2 + 1)} \right ]_{\cot^{-1} a + \varepsilon}^{\frac{\pi}{2}}\right )\\
&= \frac{2}{a} \left ( \lim_{\varepsilon\to 0} \frac{2a^2 \cot^{-1} a - 2a^2 \varepsilon - a \ln \left | \frac{-(a^2+1)\tan\varepsilon}{(1-a^2)\tan\varepsilon+2a}\right |}{2(a^2+1)} + \frac{a^2 \pi}{2(a^2+1)} - \frac{2a^2 \cot^{-1} a + 2a^2 \varepsilon - a \ln \left | \frac{(a^2+1)\tan\varepsilon}{(a^2-1)\tan\varepsilon+2a}\right |}{2(a^2 + 1)} \right )\\
&= \frac{2}{a} \left ( \lim_{\varepsilon\to 0} \frac{-4a^2 \varepsilon - a \ln \left | \frac{(1-a^2)\tan\varepsilon+2a}{(a^2-1)\tan\varepsilon+2a}\right |}{2(a^2+1)} + \frac{a^2 \pi}{2(a^2+1)}\right )\\
&= \frac{a \pi}{a^2 + 1}\\
\implies I(a) &= \int \frac{a\pi}{a^2+1} \, \mathrm{d}a\\
&= \pi \ln\sqrt{a^2 + 1} + C.
\end{align*}
Finally, observe $I(0) = 0$, so $C = 0$. Hence, $I(a) = \pi \ln\sqrt{a^2 + 1}$.
A: $\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}
A: $$
I=\int_0^{\pi/2}\ln|1-a^2\tan^2\theta|d\theta
$$

\begin{align}
I' & =\int_0^{\pi/2}\frac{2a\tan^2\theta}{a^2\tan^2\theta-1}d\theta
\\[5mm] & =\frac{2}{a}\int_0^{\pi/2}\frac{a^2\tan^2\theta}{a^2\tan^2\theta-1}d\theta
\\[5mm] & =\frac 2a\int_0^{\pi/2}1+\frac{1}{a^2\tan^2\theta-1}d\theta
\end{align}
can you do something with this? I fear it may diverge
