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.
 A: $\newcommand{\+}{^{\dagger}}
 \newcommand{\angles}[1]{\left\langle\, #1 \,\right\rangle}
 \newcommand{\braces}[1]{\left\lbrace\, #1 \,\right\rbrace}
 \newcommand{\bracks}[1]{\left\lbrack\, #1 \,\right\rbrack}
 \newcommand{\ceil}[1]{\,\left\lceil\, #1 \,\right\rceil\,}
 \newcommand{\dd}{{\rm d}}
 \newcommand{\down}{\downarrow}
 \newcommand{\ds}[1]{\displaystyle{#1}}
 \newcommand{\expo}[1]{\,{\rm e}^{#1}\,}
 \newcommand{\fermi}{\,{\rm f}}
 \newcommand{\floor}[1]{\,\left\lfloor #1 \right\rfloor\,}
 \newcommand{\half}{{1 \over 2}}
 \newcommand{\ic}{{\rm i}}
 \newcommand{\iff}{\Longleftrightarrow}
 \newcommand{\imp}{\Longrightarrow}
 \newcommand{\isdiv}{\,\left.\right\vert\,}
 \newcommand{\ket}[1]{\left\vert #1\right\rangle}
 \newcommand{\ol}[1]{\overline{#1}}
 \newcommand{\pars}[1]{\left(\, #1 \,\right)}
 \newcommand{\partiald}[3][]{\frac{\partial^{#1} #2}{\partial #3^{#1}}}
 \newcommand{\pp}{{\cal P}}
 \newcommand{\root}[2][]{\,\sqrt[#1]{\vphantom{\large A}\,#2\,}\,}
 \newcommand{\sech}{\,{\rm sech}}
 \newcommand{\sgn}{\,{\rm sgn}}
 \newcommand{\totald}[3][]{\frac{{\rm d}^{#1} #2}{{\rm d} #3^{#1}}}
 \newcommand{\ul}[1]{\underline{#1}}
 \newcommand{\verts}[1]{\left\vert\, #1 \,\right\vert}
 \newcommand{\wt}[1]{\widetilde{#1}}$
$\ds{{\rm I}\pars{a} = \int_{0}^{\pi}\ln\pars{1 - 2a\cos\pars{x} + a^{2}}\, \dd x:\
     {\large ?}.\qquad a \geq 0}$.

\begin{align}
{\rm I}\pars{a}&=\half\int_{-\pi}^{\pi}\ln\pars{1 - 2a\cos\pars{x} + a^{2}}\,\dd x
=\half\int_{\verts{z}=1 \atop {\vphantom{\Huge A}\verts{{\rm Arg}\pars{z}} < \pi}}
\ln\pars{1 - 2a\,{z^{2} + 1 \over 2z} + a^{2}}\,{\dd z \over \ic z}
\\[3mm]&=-\,\half\ic
\int_{\verts{z}=1 \atop {\vphantom{\Huge A}\verts{{\rm Arg}\pars{z}} < \pi}}
\ln\pars{-az^{2} + \bracks{a^{2} + 1}z - a \over z}\,{\dd z \over z}
\\[3mm]&=-\,\half\ic
\int_{\verts{z}=1 \atop {\vphantom{\Huge A}\verts{{\rm Arg}\pars{z}} < \pi}}
\ln\pars{-a\bracks{z - a}\bracks{z - 1/a} \over z}\,{\dd z \over z}
\\[3mm]&=-\,\half\ic
\int_{\verts{z}=1 \atop {\vphantom{\Huge A}\verts{{\rm Arg}\pars{z}} < \pi}}
\ln\pars{-a\bracks{z - \mu_{<}}\bracks{z - \mu_{>}} \over z}\,{\dd z \over z}
\quad\mbox{where}\quad
\mu_{< \atop >} \equiv {\min \atop \max}\braces{a, {1 \over a}}
\\[3mm]&\mbox{and}\quad 0\ \leq\ \mu_{<} < 1\,,\quad \mu_{>}\ >\ 1
\end{align}

$$
{\rm I}\pars{a}=
-\,\half\ic\int_{\verts{z}=1
\atop {\vphantom{\Huge A}\verts{{\rm Arg}\pars{z}} < \pi}}
\ln\pars{\bracks{z - \mu_{<}}\bracks{\mu_{>} - z}}\,{\dd z \over z}
+\half\ic\int_{\verts{z}=1 \atop {\vphantom{\Huge A}\verts{{\rm Arg}\pars{z}} < \pi}}
\ln\pars{z \over a}\,{\dd z \over z}
$$

$$
\half\ic\int_{\verts{z}=1 \atop {\vphantom{\Huge A}\verts{{\rm Arg}\pars{z}} < \pi}}
\ln\pars{z \over a}\,{\dd z \over z}
=\half\ic\int_{-\pi}^{\pi}\ln\pars{\expo{\ic\theta} \over a}\,{\expo{\ic\theta}\ic\,\dd\theta \over \expo{\ic\theta}} = \pi\ln\pars{a}
$$

\begin{align}
&\color{#c00000}{\large{\rm I}\pars{a} - \pi\ln\pars{a}}
=\half\,\ic\int_{-1}^{\mu_{<}}{\ln\pars{\bracks{\mu_{<} - x}\bracks{\mu_{>} - x}}
+ \ic\pi \over x + \ic 0^{+}}\,\dd x
\\[3mm]&\mbox{} + \half\,\ic\int_{\mu_{<}}^{-1}
{\ln\pars{\bracks{\mu_{<} - x}\bracks{\mu_{>} - x}}
- \ic\pi \over x - \ic 0^{+}}\,\dd x
\\[3mm]&=\half\,\ic\pars{\int_{-1}^{\mu_{<}}{\braces{\ln\pars{\bracks{\mu_{<} - x}\bracks{\mu_{>} - x}} + \ic\pi}}\bracks{\pp{1 \over x} - \ic\pi\delta\pars{x}}
\,\dd x}
\\[3mm]&\phantom{=}\mbox{} -\half\,\ic\pars{\int_{-1}^{\mu_{<}}{\braces{\ln\pars{\bracks{\mu_{<} - x}\bracks{\mu_{>} - x}} - \ic\pi}}\bracks{\pp{1 \over x} + \ic\pi\delta\pars{x}}\,\dd x}
\\[3mm]&=\half\ic\pp\int_{-1}^{\mu_{<}}2\pi\ic\,{\dd x \over x}
=-\pi\lim_{\epsilon \to 0^{+}}\pars{\int_{-1}^{-\epsilon}{\dd x \over x}
+\int_{\epsilon}^{\mu_{<}}{\dd x \over x}}=-\pi\ln\pars{\mu_{<}}
\\[3mm]&=\color{#c00000}{\large -\pi\Theta\pars{1 - a}\ln\pars{a} -\pi\Theta\pars{a - 1}\ln\pars{1 \over a}}
\end{align}

$$\color{#00f}{\large%
{\rm I}\pars{a} = \Theta\pars{a - 1}\bracks{2\pi\ln\pars{a}}}
$$
  which was calculated for $\ds{\color{#c00000}{a > 0}}$.

From the $\ds{{\rm I}\pars{a}}$ original definition it's clear that
$\ds{\color{#c00000}{{\rm I}\pars{a}\ \mbox{is an}\ \ul{\mbox{even}}\
\mbox{function of}\ a}}$ and that
$\ds{\color{#c00000}{{\rm I}\pars{0} = 0}}$. Then, the solution
$\ds{\color{#c00000}{\forall\ a \in {\mathbb R}}}$ is given by:
$$\color{#00f}{\large%
{\rm I}\pars{a} = \Theta\pars{\verts{a} - 1}\bracks{2\pi\ln\pars{\verts{a}}}}
$$
A: 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}$$
A: For some reason, this problem appeared on the main page for me even though the problem was posted quite a while ago. Let me present an alternative approach which does not really require any integrating.
Let us consider your integral:
$$I(a)=\int_{0}^{\pi}\ln\left(1-2a\cos(x)+a^2\right)\ \text{d}x,\;\ a>1$$
Consider a triangle $ABC$ with angles $\alpha,\beta,\gamma$ opposite to the sides $a,b,c$, respectively:

The law of cosines states
$$c^2=a^2+b^2-2ab\cos(\gamma)$$
To keep with this notation, let $b=1$ and $\gamma=x$.
Our integral becomes
$$\begin{align}
I(a) & = \int_{0}^{\pi}\ln\left(c^2\right)\ \text{d}\gamma \\
 & = 2\int_{0}^{\pi}\ln\left(c\right)\ \text{d}\gamma \\ 
\end{align}$$
The law of sines states
$$\frac{\sin(\alpha)}{a}=\frac{\sin(\beta)}{b}=\frac{\sin(\gamma)}{c}$$
Our integral becomes
$$\begin{align}
I(a) & = 2\int_{0}^{\pi}\ln\left(a\ \frac{\sin(\gamma)}{\sin(\alpha)}\right)\ \text{d}\gamma \\
 & = 2\pi \ln(a)+2\int_{0}^{\pi}\ln\left(\sin(\gamma)\right)\ \text{d}\gamma-2\int_{0}^{\pi}\ln\left(\sin(\alpha)\right)\ \text{d}\gamma \\ 
\end{align}$$
Consider the right-hand integral. In a triangle, the three angles $\alpha,\beta,\gamma$ add up to $\pi$ radians. Let $\gamma=\pi-\alpha-\beta$ such that $\text{d}\gamma=-\text{d}\alpha-\text{d}\beta$. 
When $\gamma\rightarrow 0:\alpha\rightarrow \pi,\beta\rightarrow 0$. When $\gamma\rightarrow \pi:\alpha\rightarrow 0,\ \beta\rightarrow 0$.
Our integral becomes
$$\begin{align}
I(a) & = 2\pi \ln(a)+2\int_{0}^{\pi}\ln\left(\sin(\gamma)\right)\ \text{d}\gamma\\
 & -2\left[\int_{\pi}^{0}\ln\left(\sin(\alpha)\right)(-\text{d}\alpha)+\int_{0}^{0}\ln\left(\sin(\alpha)\right)(-\text{d}\beta)\right] \\
 & = 2\pi \ln(a)+2\int_{0}^{\pi}\ln\left(\sin(\gamma)\right)\ \text{d}\gamma-2\int_{0}^{\pi}\ln\left(\sin(\alpha)\right)\ \text{d}\alpha \\ 
\end{align}$$
Recognize that the integrals evaluate to the same value and therefore will cancel out each other.
$$I(a)=2\pi\ln(a),\;\ a>1$$
A: Here is an elementary way to compute the integral.
First, let us prove some initial results.


*

*Making the substitution $x \mapsto \pi - x$ yields
$I(a) = \int^\pi_0 \log \left (1 + 2a\cos x + a^2 \right ) \, dx = I(-a)$
so that
$$I(a) = I(-a). \tag{$\dagger$}$$

*Then, consider
$$\begin{align*}
I(a) + I(-a)
&= \int^{\pi}_{0}\log \! \Big ( \left (1 - 2a\cos x + a^2 \right ) \left (1 + 2a\cos x + a^2 \right ) \Big) \> dx\\
&= \int^{\pi}_{0}\log \! \Big ( \left (1 + a^2 \right )^2 - \left (2a\cos x \right )^2 \Big) \> dx.\\
\end{align*}$$
Using double angle formulae produces
$$\begin{align*}
I(a) + I(-a)&= \int^{\pi}_{0}\log \left ( 1 + 2a^2 + a^4 - 2a^2 \left ( 1 + \cos 2x \right ) \right) \, dx\\
&= \int^{\pi}_{0}\log \left ( 1 - 2a^2\cos 2x + a^4 \right) \, dx,\\
\end{align*}$$
so we may let $x \mapsto \frac{1}{2}x$ to give
$$\begin{align*}
I(a) + I(-a) &= \frac{1}{2}\int^{2\pi}_{0}\log \left ( 1 - 2a^2\cos x + a^4 \right) \, dx.\\
\end{align*}$$
We can then split the integral at $\pi$ and set $x \mapsto 2\pi - x$ for the second integral:
$$\begin{align*}
I(a) + I(-a) &= \frac{1}{2} I(a^2) + \frac{1}{2}\int^{2\pi}_{\pi}\log \left ( 1 - 2a^2\cos x + a^4 \right) \, dx\\
&= \frac{1}{2} I(a^2) + \frac{1}{2}\int^{\pi}_{0}\log \left ( 1 - 2a^2\cos x + a^4 \right) \, dx\\
&= I(a^2).
\end{align*}$$
We thus have (applying $(\dagger)$)
$$I(a)= \frac{1}{2}I(a^2). \tag{$\star$}$$

It follows from $(\star)$ that $I(0) = 0$ and $I(1) = 0$.
Consider the case when $0 \le a < 1$. We may use $(\star)$ iteratively $n$ times to write
$$I(a) = \frac{1}{2^n} I \left ( a^{2^{n}} \right ). $$
Setting $n \to \infty$ allows $\frac{1}{2^n} \to 0$ and $a^{2^{n}} \to 0$ so that $I \left ( a^{2^{n}} \right ) \to 0$ which gives the result
$$ I(a) = 0. $$
When $a > 1$, it follows that $0 < 1/a < 1$ and consequently $I(1/a) = 0$. We have
$$\begin{align*}
I(a) &= \int^\pi_0 \log \! \Big ( a^2 \left ((1/a)^2 + (1/a)\cos x + 1 \right ) \Big ) \> dx\\
&= 2\pi\log(a) + I(1/a)\\
&= 2\pi\log\left(a\right).
\end{align*}$$
We could use $(\dagger)$ to extend the result to negative $a$, obtaining the final solution valid for all real $a$,
$$I(a) = 
\begin{cases}
0 &\text{if } |a| \le 1;\\
2\pi\log|a| &\text{otherwise}.
\end{cases}$$
A: 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.
$$
A: If 
$$I(a)=\int_{0}^{\pi}\ln\left(1-2a\cos x+a^2\right)\ \mathrm{d}x,$$ then
\begin{align}
I'(a)&=\int_{0}^{\pi}\frac{2a-2\cos x}{1-2a\cos x+a^2} \ \mathrm{d}x,\\
I'(a) & = \frac{1}{a}\int_{0}^{\pi}\frac{2a^2-2a\cos x}{1-2a\cos x+a^2} \ \mathrm{d}x \\
& = \frac{1}{a}\int_{0}^{\pi}\frac{1-1+a^2+a^2-2a\cos x}{1-2a\cos x+a^2} \ \mathrm{d}x \\
& = {\pi \over a} + \frac{1}{a}\int_{0}^{\pi}\frac{a^2-1}{1-2a\cos x+a^2} \ \mathrm{d}x
\end{align}
and making the Weierstrass substitution, $$\cos x  = \frac{1 - t^2}{1 + t^2}, $$
$$\mathrm{d}x  = \frac{2 \,\mathrm{d}t}{1 + t^2}.$$
$$I'(a)={\pi \over a} + \frac{2}{a}\int_{0}^{\infty}\frac{a^2-1}{(1+a^2)(1+t^2)-2a(1-t^2)}\ \mathrm{d}t $$ $$I'(a)={\pi \over a} + \frac{2}{a}\int_{0}^{\infty}\frac{a^2-1}{(1-a)^2 + (1+a)^2t^2} \ \mathrm{d}t$$
$$I'(a)={\pi \over a} + \frac{\pi}{a} \operatorname{sgn} (a^2-1),$$
so for $a > 1$, 
$$I'(a)={2\pi \over a},$$
$$I(a)={2 \pi \log a},$$ given that $\displaystyle \lim_{a \rightarrow 1^+} I(a)=0$. You have to be careful to show this last statement I believe, but you can see the result here - this integral is easy to evaluate:
\begin{align}
\int_0^{\pi} \log(2-2\cos x) \ \mathrm{d}x &= \int_0^{\pi} \log(4 \sin^2 x) \ \mathrm{d}x \\
& = \pi \log 4 + 2\int_0^{\pi} \log(\sin x) \ \mathrm{d}x \\
& = 2\pi \log 2 + 4\int_0^{\pi/2} \log(\sin x) \ \mathrm{d}x \\
\end{align}
That final integral can be found here, which gives us the final result. 
A: By my post, I had found
$$
\int_{0}^{\pi} \ln (b \cos x+c)=\pi \ln \left(\frac{c+\sqrt{c^{2}-b^{2}}}{2}\right) \tag*{(*)} 
$$
for any $c\neq 0$ and $-1\leq \frac{b}{c} \leq 1.$
Putting $b=-2 a$ and $c=a^{2}+1$ into $(*)$, we have
$$
\begin{aligned}
\int_{0}^{\pi} \ln \left(1-2 a \cos x+a^{2}\right) d x =& \pi \ln \left(\frac{a^{2}+1+\sqrt{\left(a^{2}+1\right)^{2}-4 a^{2}}}{2}\right) \\
=& \pi \ln \left(\frac{a^{2}+1+\sqrt{\left(a^{2}-1\right)^{2}}}{2}\right) \\
=& \pi \ln \left(\frac{a^{2}+1+\left|a^{2}-1\right|}{2}\right)
\end{aligned}
$$
We can now conclude that
For any $|a| \leqslant 1$,
$$
I=\pi \ln \left(\frac{\left.a^{2}+1+1-a^{2}\right)}{2}\right)=0
$$
for any $|a|>1$,
$$
I=\pi \ln \left(\frac{a^{2}+1+a^{2}-1}{2}\right)=2 \ln |a|
$$
