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.

$$
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
