Evaluating $\int_{0}^{\pi}\ln (1+\cos x)\, dx$ [duplicate]

The problem is

$$\int_{0}^{\pi}\ln (1+\cos x)\ dx$$

What I tried was using standard limit formulas like changing $x$ to $\pi - x$ and I also tried integration by parts on it to no avail. Please help. Also this is my first question so please tell if I am wrong somewhere.


$$\begin{eqnarray*}\int_{0}^{\pi}\log(1+\cos x)\,dx &=& \int_{0}^{\pi/2}\log(1+\cos x)\,dx+\int_{0}^{\pi/2}\log(1+\cos(\pi-x))\,dx\\ &=& \int_{0}^{\pi/2}\log(\sin^2 x)\,dx=\int_{0}^{\pi}\log(\sin x)\,dx \tag{1}\end{eqnarray*}$$ And by a notorious identity: $$ \prod_{k=1}^{n-1}\sin\frac{k\pi}{n} = \frac{2n}{2^n},\tag{2}$$ hence the RHS of $(1)$ can be computed as a Riemann sum: $$ \int_{0}^{\pi}\log(\sin x)\,dx = \lim_{n\to +\infty}\frac{\pi}{n}\sum_{k=1}^{n-1}\log\sin\frac{\pi k}{n}=\color{red}{-\pi \log 2}.\tag{3}$$ There is also a well-known proof through symmetry: $$ \begin{eqnarray*}I=\int_{0}^{\pi}\log(\sin x)&=&2\int_{0}^{\pi/2}\log(\sin(2t))\,dt=2\int_{0}^{\pi/2}\log(2\sin t\cos t)\,dt\\&=&\pi\log 2+2\int_{0}^{\pi/2}\log(\sin t)\,dt+2\int_{0}^{\pi/2}\log(\cos t)\,dt\\&=&\pi \log 2 + 2I\tag{4}\end{eqnarray*}$$ from which $I=-\pi\log 2$ immediately follows.


Using Fourier Series

As shown in this answer, $$ \log(1+\cos(x))=2\sum_{k=1}^\infty(-1)^{k-1}\frac{\cos(kx)}{k}-\log(2)\tag{1} $$ For all $k\in\mathbb{Z}\setminus\{0\}$ $$ \int_0^\pi\cos(kx)\,\mathrm{d}x=0\tag{2} $$ Therefore, $$ \int_0^\pi\log(1+\cos(x))\,\mathrm{d}x=-\pi\log(2)\tag{3} $$


A More Elementary Approach

$$ \begin{align} \int_0^\pi\log(1+\cos(x))\,\mathrm{d}x &=\int_0^\pi\log\left(2\cos^2\left(\frac x2\right)\right)\,\mathrm{d}x\\ &=\pi\log(2)+\int_0^\pi\log\left(\cos^2\left(\frac x2\right)\right)\,\mathrm{d}x\\ &=\pi\log(2)+2\int_0^{\pi/2}\log\left(\cos^2(x)\right)\,\mathrm{d}x\tag{4} \end{align} $$ and $$ \begin{align} \int_0^\pi\log(1-\cos(x))\,\mathrm{d}x &=\int_0^\pi\log\left(2\sin^2\left(\frac x2\right)\right)\,\mathrm{d}x\\ &=\pi\log(2)+\int_0^\pi\log\left(\sin^2\left(\frac x2\right)\right)\,\mathrm{d}x\\ &=\pi\log(2)+2\int_0^{\pi/2}\log\left(\sin^2(x)\right)\,\mathrm{d}x\tag{5} \end{align} $$ By substituting $x\mapsto\pi-x$, we see that the left side of $(4)$ equals the left side of $(5)$. Therefore, $$ \begin{align} 2\int_0^\pi\log(1+\cos(x))\,\mathrm{d}x &=\int_0^\pi\log(1+\cos(x))\,\mathrm{d}x+\int_0^\pi\log(1-\cos(x))\,\mathrm{d}x\tag{6}\\ &=\int_0^\pi\log\left(\sin^2(x)\right)\,\mathrm{d}x\tag{7}\\ &=2\int_0^\pi\log(1-\cos(x))\,\mathrm{d}x\tag{8}\\ &=2\pi\log(2)+4\int_0^{\pi/2}\log\left(\sin^2(x)\right)\,\mathrm{d}x\tag{9}\\ &=2\pi\log(2)+2\int_0^\pi\log\left(\sin^2(x)\right)\,\mathrm{d}x\tag{10}\\ &=-2\pi\log(2)\tag{11} \end{align} $$ Explanation:
$\phantom{1}(6)$: the left side of $(4)$ equals the left side of $(5)$
$\phantom{1}(7)$: add the integrands
$\phantom{1}(8)$: twice the left side of $(4)$ equals twice the left side of $(5)$
$\phantom{1}(9)$: apply $(5)$
$(10)$: $\sin(x)=\sin(\pi-x)$
$(11)$: $2$ times $(7)$ minus $(10)$

Thus, dividing $(11)$ by $2$, we get $$ \int_0^\pi\log(1+\cos(x))\,\mathrm{d}x=-\pi\log(2)\tag{12} $$


Another way to solve is to use the Cauchy Integral Formula $$ f(z)=\frac{1}{2\pi i}\int_{D}\frac{f(\xi)}{\xi-z}d\xi$$ where $f(z)$ is analytic in $D$ and continuous in $\bar{D}$. Note that $$ |1+\cos t+i\sin t|^2=2(1+\cos t).$$ So \begin{eqnarray} &&\int_{0}^\pi\log(1+\cos t)\; dt\\ &=&\frac12\int_{0}^{2\pi}\log(1+\cos t)\; dt\\ &=&\frac12\int_{0}^{2\pi}\log|1+\cos t+i\sin t|\; dt-\pi\log2\\ &=&\frac12\int_{0}^{2\pi}\Re\left[\log(1+\cos t+i\sin t)\right]\; dt-\pi\log2\\ &=&\frac12\Re\left[\int_{0}^{2\pi}\log(1+\cos t+i\sin t)\; dt\right]-\pi\log2\\ &=&\frac12\Re\left[\int_{|z|=1}\log(1+z)\; \frac{dz}{iz}\right]-\pi\log2\\ &=&\frac12\times2\pi \log 1-\pi\log2\\ &=&-\pi\log2. \end{eqnarray}