Computing $\int_{0}^{\pi}\ln\left(1-2a\cos x+a^2\right) \, dx$ 
For $a\ge 0$ let's define $$I(a)=\int_{0}^{\pi}\ln\left(1-2a\cos x+a^2\right)dx.$$ Find explicit formula for $I(a)$.

My attempt: Let
$$\begin{align*}
f_n(x)
&= \frac{\ln\left(1-2
\left(a+\frac{1}{n}\right)\cos x+\left(a+\frac{1}{n}\right)^2\right)-\ln\left(1-2a\cos x+a^2\right)}{\frac{1}{n}}\\
&=\frac{\ln\left(\displaystyle\frac{1-2
\left(a+\frac{1}{n}\right)\cos x+\left(a+\frac{1}{n}\right)^2}{1-2a\cos x+a^2}\right)}{\frac{1}{n}}\\
&=\frac{\ln\left(1+\dfrac{1}{n}\left(\displaystyle\frac{2a-2\cos x+\frac{1}{n}}{1-2a\cos x+a^2}\right)\right)}{\frac{1}{n}}.
\end{align*}$$
Now it is easy to see that $f_n(x) \to \frac{2a-2\cos x}{1-2a\cos x+a^2}$ as $n \to \infty$. $|f_n(x)|\le \frac{2a+2}{(1-a)^2}$ RHS is integrable so $\lim_{n\to\infty}\int_0^\pi f_n(x)dx = \int_0^\pi \frac{2a-2\cos x}{1-2a\cos x+a^2} dx=I'(a)$. But 
$$\int_0^\pi \frac{2a-2\cos x}{1-2a\cos x+a^2}=\int_0^\pi\left(1-\frac{(1-a)^2}{1-2a\cos x+a^2}\right)dx.$$ Consider
$$\int_0^\pi\frac{dx}{1-2a\cos x+a^2}=\int_0^\infty\frac{\frac{dy}{1+t^2}}{1-2a\frac{1-t^2}{1+t^2}+a^2}=\int_0^\infty\frac{dt}{1+t^2-2a(1-t^2)+a^2(1+t^2)}=\int_0^\infty\frac{dt}{(1-a)^2+\left((1+a)t\right)^2}\stackrel{(*)}{=}\frac{1}{(1-a)^2}\int_0^\infty\frac{dt}{1+\left(\frac{1+a}{1-a}t\right)^2}=\frac{1}{(1-a)(1+a)}\int_0^\infty\frac{du}{1+u^2}=\frac{1}{(1-a)(1+a)}\frac{\pi}{2}.$$
So $$I'(a)=\frac{\pi}{2}\left(2-\frac{1-a}{1+a}\right)\Rightarrow I(a)=\frac{\pi}{2}\left(3a-2\ln\left(a+1\right)\right).$$
It looks too easy, is there any crucial lack?
$(*)$ — we have to check $a=1$ here by hand and actually consider $[0,1), (1,\infty)$ but result on these two intervals may differ only by constant - it may be important but in my opinion not crucial for this proof.

Considering the following diagram:
$\hspace{2cm}$
we get that
$$
\begin{align}
\int_0^\pi\log\left(1-2r\cos(\theta)+r^2\right)\,\mathrm{d}\theta
&=\int_0^{2\pi}\log\sqrt{1-2r\cos(\theta)+r^2}\,\mathrm{d}\theta\\
&=\mathrm{Re}\left(\int_\gamma\log(z-1)\frac{\mathrm{d}z}{iz}\right)
\end{align}
$$
along the path $\gamma=r\,e^{i[0,2\pi]}$.
If $r\le1$, the singularity at $z=0$ has residue $0$. Thus, the integral is $0$.
If $r\gt1$, then we need to modify the path to avoid the branch cut for $\log(z-1)$ along $\{t\in\mathbb{R}:t\ge1\}$. That is, in addition to the circular contour $\gamma=r\,e^{i[0,2\pi]}$, we need to follow the two contours $[r,1]$ below the real axis and $[1,r]$ above the real axis. The sum of the integrals along these two contours is
$$
\int_r^12\pi i\frac{\mathrm{d}z}{iz}+\int_1^r0\frac{\mathrm{d}z}{iz}=-2\pi\log(r)
$$
Since the integral along all three contours is $0$, the integral along the circular part must be $2\pi\log(r)$.
Putting these two cases together, we get
$$
\int_0^\pi\log\left(1-2r\cos(\theta)+r^2\right)\,\mathrm{d}\theta
=\left\{\begin{array}{l}
0&\text{if }r\le1\\
2\pi\log(r)&\text{if }r\gt1
\end{array}\right.
$$
