Evaluate integral: $\int_0^{\frac{\pi}{2}}\ln(a^2\cos^2 x +b^2\sin^2x)dx$? For $a,b>0$, show that

$$\int_0^{\frac{\pi}{2}}\ln(a^2\cos^2 x+b^2\sin^2 x) dx=\pi\ln\left(\frac{a+b}{2}\right)$$
I came across to this problem in the book Table of integrals, series and product. So here is my try to prove the closed form.

For $a>b$ then, we can write the    $$ a^2\cos^2x +b^2\sin^2x =b^2\cos^2x+b^2\sin^2x + k\cos^2x = b^2 +k\cos^2x $$ where $ k= a^2-b^2$ and similarly, for $ b>a$  we can write $a^2\cos^2x +b^2\sin^2x = a^2+l\sin^2x$ where $l= b^2-a^2$. Hence we have $$ \int_0^{\frac{\pi}{2}}\ln(b^2+k\cos^2x )dx=\\
\int_0^{\frac{\pi}{2}}\left(\ln(b^2) + \ln\left(1+\frac{k}{b^2}\cos^2x\right)\right)dx\cdots(1)$$ and $$\int_0^{\frac{\pi}{2}}\ln(a^2+l\sin^2x )dx \\= \int_0^{\frac{\pi}{2}}\left(\ln(a^2) + \ln\left(1+\frac{l}{a^2}\sin^2x\right)\right)dx, \; \; b>a$$ Since $\left| \frac{k}{b^2}\cos^2 x\right|\leq 1$ so we use the Machlaurin series of $\ln(1+x)$ for $|x|<1$ giving us $$ \pi \ln(b)+\sum_{m\geq 1} \frac{(-1)^{m-1}}{m}\left(\frac{k}{4b^2}\right)^m\int_0^{\frac{\pi}{2}}\cos^{2m}xdx$$ The latter integral is well know result know as Wallis integral thus gives us $$ \frac{\pi}{2}\sum_{m\geq 1} \frac{(-1)^{m+1}}{m}\left(\frac{k}{4b^2}\right)^m{2m\choose m}\cdots(2)$$ Recalling the generating function of Central  binomial coefficients for $|y| <\frac{1}{4}$, ie $$\sum_{m\geq 1} {2m\choose m} y^{m}=\frac{1}{\sqrt{1-4y}}-1.$$ Dividing by $y$ and an integrating  from $0$ to $z$ we have $$ \sum_{m\geq 1}\frac{1}{m}{2m\choose m} z^{m} =-2\ln\left(\frac{\sqrt{1-4z}+1}{2}\right) $$ multiplying thoroughly by $-1$ and set $z=-\frac{k}{4b^2}=-\frac{a^2-b^2}{4b^2}$ gives us $$\sum_{m\geq 1} \frac{(-1)^{m+1}}{m}\left(\frac{k}{4b^2}\right)^m{2m\choose m}\\ = 2\ln\left(\frac{{a+b}}{2}\right)-2\ln b $$ From $(1)$ and $(2)$ we have $$\pi\ln(b)+\pi\ln\left(\frac{a+b}{2}\right)-\pi\ln b \\= \pi\ln\left(\frac{a+b}{2}\right)$$ Similarly, for the case of $b>a$ we replace $ \cos^2x$ by $\sin^2x$, $k$ by $ l$. We obtained the same desired result.  Moreover,   we can also have the following  result.

$$\int_0^{\frac{\pi}{2}}\ln(a^2\cos^2 x+b^2\sin^2 x) dx=\frac{1}{2}\int_0^{\pi}\ln(a^2\cos^2x+b^2\sin^2x)dx=\pi\ln\left(\frac{a+b}{2}\right)$$

Now I'm wishing to know other different approaches/proofs for the aforementioned integral.
Thank you.
 A: I thought it might be instructive to present an approach that relies on contour integration in the complex plane.  To that end, we proceed.


MODIFYING THE INTEGRAL
Let $I(a,b)$ be defined by the integral
$$I(a,b)=\int_0^{\pi/2}\log(a^2\cos^2(x)+b^2\sin^2(x))\,dx\tag1$$
Using the double angle formulas, $\sin^2(x)=\frac{1-\cos(2x)}{2}$ and $\cos^2(x)=\frac{1+\cos(2x)}{2}$, in $(1)$ we obtain
$$\begin{align}
I(a,b)&=\int_0^{\pi/2}\log\left(\frac{a^2+b^2}2+\frac{a^2-b^2}{2}\cos(2x)\right)\,dx\tag2\\\\
&=\frac\pi2 \log\left(\frac{a^2+b^2}{2}\right)+\frac14 \int_{-\pi}^{\pi} \log\left(1+\alpha\cos(x)\right)\,dx\tag3
\end{align}$$
In going from $(2)$ to $(3)$ we enforced the substitution $x\mapsto x/2$ and exploited the evenness of the integrand.
From here, we could use Feynman's trick, differentiate under the integral (tangent half-angle or contour integration), evaluate the integral of the derivative, and finish by integrating.  Instead, we will apply contour integration to directly evaluate the integral.


MOVING TO THE COMPLEX PLANE
Next, we transform the integration on the right-hand side of $(3)$ to the complex plane through the substitution $z=e^{ix}$ to obtain
$$\begin{align}
\int_{-\pi}^{\pi} \log\left(1+\alpha\cos(x)\right)\,dx&=\oint_{|z|=1}\log\left(\frac{\alpha(z^2+2z/\alpha+1)}{2z}\right)\,\frac1{iz}\,dz\tag4
\end{align}$$
where $-1<\alpha =\frac{a^2-b^2}{a^2+b^2}<1$.

We select the principal branch of the logarithm with branch cuts emanating from branch points, extending along the negative real axis, and terminating at $z=-\infty$.

Denote the roots of $z^2+2z/\alpha+1=0$ by $r_1$ and $r_2$.

We will assume that $a<b$ so that $-1<r_1=\frac{a-b}{a+b}<0$ lies inside the unit circle $|z|=1$ while $r_2=\frac{a+b}{a-b}<-1$ lies outside the unit circle.

Then, we have from $(4)$
$$\begin{align}
\oint_{|z|=1}\log\left(\frac{\alpha(z^2+2z/\alpha+1)}{2z}\right)\,\frac1{iz}\,dz&=\oint_{|z|=1} \frac{\log\left(-\alpha/2\right)}{iz}\,dz-\oint_{|z|=1} \frac{\log\left(z\right)}{iz}\,dz\\\\
&+\oint_{|z|=1} \frac{\log\left(z-r_1\right)}{iz}\,dz+\oint_{|z|=1} \frac{\log\left(z-r_2\right)}{iz}\,dz\tag5
\end{align}$$
where the negative sign on $\alpha$ is required to ensure that the sum of the arguments of the logarithms is $0$ on the unit circle.


EVALUATING THE INTEGRALS IN $(5)$

From the residue theorem, we see that
$$\oint_{|z|=1} \frac{\log\left(\alpha/2\right)}{iz}\,dz=2\pi \log\left(\alpha/2\right)\tag6$$

From Cauchy's Integral Theorem, we have
$$\begin{align}\oint_{|z|=1}\frac{\log(z)}{z}\,dz&=\lim_{\varepsilon\to0}\left(\int_{-1}^{-\varepsilon}\frac{(\log(-x)-i\pi)-(\log(-x)+i\pi)}{ix}\,dx+\int_{-\pi}^\pi \frac{\log(\varepsilon e^{i\phi})}{i\varepsilon e^{i\phi}}\,d\phi\right)\\\\
&=0\tag7
\end{align}$$

From the residue theorem, we find that
$$\begin{align}
\oint_{|z|=1}\frac{\log(z-r_2)}{iz}\,dz&=2\pi \log(-r_2)\tag8
\end{align}$$

Finally, from Cauchy's Integral Theorem, we have
$$\begin{align}
\oint_{|z|=1}\frac{\log(z-r_1)}{iz}\,dz&=2\pi \log(-r_1)\\\\
&+\lim_{\varepsilon\to0}\left(\int_{-1}^{r_1-\varepsilon}\frac{(\log(-(x-r_1)) -i\pi)-(\log(-(x-r_1))+i\pi)}{ix}\,dx\\\\+\int_{-\pi}^{\pi} \frac{\log(\varepsilon e^{i\phi})}{i(r_1+\varepsilon e^{i\phi})}\,i\varepsilon e^{i\phi}\,d\phi\right)\\\\
&=0\tag9
\end{align}$$


PUTTING IT ALL TOGETHER
Using $(6)-(9)$, we find that
$$\begin{align}
I(a,b)&=\frac\pi2 \log\left(\frac{a^2+b^2}{2}\right)+\frac\pi2 \log(-\alpha/2)+\frac\pi2\log(-r_2)\\\\
&=\pi\log\left(\frac{a+b}{2}\right)
\end{align}$$
which agrees with the expected result!
A: Let
$$ I(a)=\int_{0}^{\frac{\pi}{2}} \ln(a^2 \cos^2 x+b^2 \sin^2 x) dx $$
Thus
$$ I(b)=\int_{0}^{\frac{\pi}{2}} \ln(b^2 \cos^2 x+b^2 \sin^2 x) dx=\pi \ln b $$
\begin{align}
I'(a)&=\int_{0}^{\frac{\pi}{2}} \frac{2a\cos^2 x}{a^2 \cos^2 x+b^2 \sin^2 x}dx \\
&=2a \int_{0}^{\frac{\pi}{2}} \frac{d(\tan x)}{(a^2+b^2 \tan^2 x)(1+\tan^2 x)} \\
&=\frac{\pi}{a+b} \\
\end{align}
Thus
$$ \int_b^a I'(a) da=\int_b^a \frac{\pi}{a+b} da $$
$$ I(a)-I(b)=\pi (\ln(a+b)-\ln(2b)) $$
$$ I(a)=\pi \ln \frac{a+b}{2} $$
