evaluation of $\int \cos (2x)\cdot \ln \left(\frac{\cos x+\sin x}{\cos x-\sin x}\right)dx$

Let

\begin{equation*} I=\int \cos 2x\cdot\ln \left|\frac{\cos x+\sin x}{\cos x-\sin x}\right|\,dx. \end{equation*}

Using the following identity

\begin{equation*} \cos 2x=2\cos ^{2}x-1 \end{equation*}

and the substitution

\begin{equation*} u=\cos x, \end{equation*}

we get

\begin{equation*} I=\int \frac{1-2u^{2}}{\sqrt{1-u^{2}}}\cdot\ln \left|\frac{u+\sqrt{1-u^{2}}}{u-\sqrt{1-u^{2}}}\right|\,du. \end{equation*}

$I$ is integrable by parts, differentiating the factor $\ln \left|\frac{u+\sqrt{1-u^{2}}}{u-\sqrt{1-u^{2}}}\right|$ and integrating the factor $\frac{1-2u^{2}}{\sqrt{1-u^{2}}}$. After simplifying, we obtain

\begin{eqnarray*} I &=&u\sqrt{1-u^{2}}\cdot\ln \left|\frac{u+\sqrt{1-u^{2}}}{u-\sqrt{1-u^{2}}}\right|+2\int \frac{u}{2u^{2}-1}du \\[2ex] &=&u\sqrt{1-u^{2}}\cdot\ln \left|\frac{u+\sqrt{1-u^{2}}}{u-\sqrt{1-u^{2}}}\right|+\frac{1}{2} \ln \left| 2u^{2}-1\right| +C \\[2ex] &=&\left( \cos x\cdot\sin x\right)\cdot \ln \left|\frac{\cos x+\sin x}{\cos x-\sin x}\right|+\frac{1 }{2}\ln \left| 2\cos ^{2}x-1\right| +C\\[2ex] &=&\frac{\sin 2x }{2} \ln \left|\frac{\cos x+\sin x}{\cos x-\sin x}\right|+\frac{\ln \left| \cos 2x\right| }{2} +C. \end{eqnarray*}


Integrate by parts: $\int udv=uv-\int v du$, where $$u=\ln\frac{\cos x+\sin x}{\cos x-\sin x}\Rightarrow du=\frac{\frac{(\cos x-\sin x)(-\sin x+\cos x)-(\cos x+\sin x)(-\sin x +\cos x) }{(\cos x-\sin x)^2}}{\frac{\cos x+\sin x}{\cos x-\sin x}}=...=\frac{2}{\cos 2x}dx$$ and $$ dv=\cos 2x dx \Rightarrow v=\frac{1}{2}\sin 2x.$$ Then, $$\int \cos 2x \ln(\frac{\cos x+\sin x}{\cos x-\sin x}) dx=\frac{1}{2}\sin 2x \ln\frac{\cos x+\sin x}{\cos x-\sin x}-\int \frac{1}{2}\sin 2x \frac{2}{\cos 2x} dx=$$ $$=\frac{1}{2}\sin 2x\ln \frac{\cos x+\sin x}{\cos x-\sin x}-\int \tan 2x dx= $$ $$=\frac{1}{2}\sin 2x \cdot\ln\left(\frac{\cos x+\sin x}{\cos x-\sin x}\right)-\frac{1}{2}\ln|\sec 2x|+c. $$


Let's recall the definition of the Inverse Hyperbolic Tangent: $$\begin{cases}\operatorname{arctanh}(x)=\frac{1}{2}\ln\left(\frac{1+x}{1-x}\right)\\\frac{d}{dx}\operatorname{arctanh}(x)=\frac{1}{1-x^2}\end{cases}; x\in(-1,1)$$

So, the integral can be rewritten as: $$\require{cancel}\begin{align}\int\cos(2x)\log\left(\frac{\cos(x)+\sin(x)}{\cos(x)-\sin(x)}\right)dx &=\color{red}{2}\int\cos(2x)\color{red}{\frac{1}{2}}\log\left(\frac{\cancel{\cos(x)}}{\cancel{\cos(x)}}\left(\frac{1+\frac{\sin(x)}{\cos(x)}}{1-\frac{\sin(x)}{\cos(x)}}\right)\right)dx\\&=2\int\cos(2x)\operatorname{arctanh}\left(\tan(x)\right)dx\\&= \sin(2x)\operatorname{arctanh}\left(\tan(x)\right)-\int\frac{\sin(2x)}{1-\tan^2(x)}\sec^2(x)dx\\&= \sin(2x)\operatorname{arctanh}\left(\tan(x)\right)-\int\frac{\sin(2x)\cancel{\cos^2(x)}\cancel{\sec^2(x)}}{\underbrace{\cos^2(x)-\sin^2(x)}_{\cos(2x)}}dx\\&= \sin(2x)\operatorname{arctanh}\left(\tan(x)\right)+\frac{\log\left|\cos(2x)\right|}{2}+C\end{align}$$