<s>[INST] 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.
 [/INST] Old thread, but this question came up again and was marked a duplicate, so I have to post my physics lecture here.  
You know the symmetries of the problem that the electric field of a line charge must be purely radial and that its magnitude has no axial or azimuthal dependence $\vec E=E(r)\hat e_r$. Thus we may apply Gauss's law over a cylinder or radius $r$ and length $\ell$ to find the magnitude of the electric field of a line charge $\lambda$ coincident with the $z$-axis:
$$\oint\vec E\cdot d^2\vec A=E(r)A_{\text{curvy}}=2\pi rE(r)=\int\frac{\rho}{\epsilon_0}d^3V=\frac{\lambda\ell}{\epsilon_0}$$
So $\vec E=\frac{\lambda}{2\pi\epsilon_0r}\hat e_r=-\vec\nabla V$. So we can get the potential $V=-\frac{\lambda}{2\pi\epsilon_0}\ln r+C$. Now that constant of integration is a bit problematic because $V$ is unbounded at both $r=0$ and $r=\infty$, but if we have a line charge $\lambda$ at $(x,y)=(b\cos\theta,b\sin\theta)$ and another charge $-\lambda$ on the $z$-axis, then the potential of the combination is
$$V(\theta)=-\frac{\lambda}{2\pi\epsilon_0}\ln\sqrt{1-2\frac br\cos\theta+\frac{b^2}{r^2}}$$
And this potential does go to $0$ as $r$ goes to $\infty$. Now we can create the potential for a cylinder centered on the $z$-axis with radius $b$ and surface charge density $\sigma$ with a line charge $-2\pi b\sigma$ running along the $z$-axis by superposition:
$$V=\int_0^{2\pi}-\frac{a\sigma}{4\pi\epsilon_0}\ln\left(1-2\frac br\cos\theta+\frac{b^2}{r^2}\right)d\theta$$
For $r>b$, applying Gauss's law over a cylinder of radius $r$ and length $\ell$ this time shows that $\vec E=\vec0$ because the cylinder contains no net charge. So this time $V=C$, a constant for $r>b$. Since
$$\lim_{r\rightarrow\infty}V(r)=0$$ by construction, so we have shown that for $0<a<1$,
$$\int_0^{2\pi}\ln(1-2a\cos\theta+a^2)d\theta=0$$
If $a>1$, then
$$\begin{align}\int_0^{2\pi}\ln(1-2a\cos\theta+a^2)d\theta&=\int_0^{2\pi}\left[2\ln a+\ln(1-2a^{-1}\cos\theta+a^{-2})\right]d\theta\\
&=4\pi\ln a+0=4\pi\ln a\end{align}$$
</s>