Mathematica gives
$$g(a)=\frac{\pi}{2} \,  \text{sgn}(a) \ln(1+|a|)
$$
for real $a$. 

This can be obtained as follows: $g(0)=0$ and 
$$g'(a)=\int_0^{\pi/2}\frac{dx}{1+a^2\tan^2 x}=\int_0^\infty\frac{du}{(1+a^2u^2)(1+u^2)}=\frac{\pi/2}{1+|a|},
$$
where we used the substitution $u=\tan x$; 
the latter integral can be taken by partial fraction decomposition: 
$$\frac1{(1+a^2u^2)(1+u^2)}=\frac{1}{\left(1-a^2\right)
   \left(1+u^2\right)} - 
\frac{a^2}{(1-a^2) \left(1+a^2 u^2\right)}
$$
for real $a$ with $|a|\ne1$; the case $|a|=1$ can be obtained by continuity.