Possible Mistake in Evaluating $\operatorname{P.V.}\int_{0}^{\pi}\tan\left(x\right)\ln\left(\cos^{2}\left(x\right)\right)dx$ (Motivation) In an attempt to answer this question, I have stumbled upon a contour integral I currently am having trouble with. For context, I am trying to prove
$$\operatorname{P.V.}\int_{0}^{\pi}\tan\left(x\right)\ln\left(\cos^{2}\left(x\right)\right)dx = 0.$$
(Attempt)  Let $f(z) = \tan\left(z\right)\ln\left(\cos^{2}\left(z\right)\right)$ and define a contour $C = [0,\pi/2 - \epsilon] \cup \psi \cup [\pi/2+\epsilon, \pi] \cup [\pi, \pi + ib] \cup [\pi + ib, ib] \cup [ib, 0]$ that we will traverse counterclockwise around. Suppose $\epsilon > 0$ is small, $b>\epsilon$, and $\psi$ is the indented semi-circular path enclosing $z=\pi/2$ with a radius of $\epsilon$.
By Cauchy's Residue Theorem, we write $\displaystyle \oint_{C} f(z)dz$ as
$$
\eqalign{
0 &= \int_{0}^{\pi/2 - \epsilon}f(z)dz + \int_{\psi}f(z)dz + \int_{\pi/2 + \epsilon}^{\pi}f(z)dz + \int_{\pi}^{\pi+ib}f(z)dz + \int_{\pi+ib}^{ib}f(z)dz+\int_{ib}^{0}f(z)dz \cr
\operatorname{P.V.}\int_{0}^{\pi}f(z)dz &= \lim_{\epsilon \to 0}\int_{-\psi}f(z)dz + \int_{0}^{ib}f(z)dz - \int_{\pi}^{\pi+ib}f(z)dz + \int_{ib}^{\pi+ib}f(z)dz.
}
$$
After a bit of struggling, I was able to evaluate $\displaystyle \int_{0}^{ib}f(z)dz$, $\displaystyle\int_{\pi}^{\pi+ib}f(z)dz$, and $\displaystyle\int_{ib}^{\pi+ib}f(z)dz$. However, this next part is something I am skeptical about:

$$
\eqalign{
\int_{-\psi}\tan\left(z\right)\ln\left(\cos^{2}\left(z\right)\right)dz &= \int_{0}^{\pi}\tan\left(\frac{\pi}{2}+\epsilon e^{i\theta}\right)\ln\left(\cos^{2}\left(\frac{\pi}{2}+\epsilon e^{i\theta}\right)\right)d\left(\frac{\pi}{2}+\epsilon e^{i\theta}\right) \cr
&= \int_{0}^{\pi}-\epsilon ie^{i\theta}\cot\left(\epsilon e^{i\theta}\right)\ln\left(\sin^{2}\left(\epsilon e^{i\theta}\right)\right)d\theta \cr
&= \int_{-\epsilon}^{\epsilon}\cot\left(u\right)\ln\left(\sin^{2}\left(u\right)\right)du \cr 
}
$$
which approaches $0$ as $\epsilon \to 0$.

(Question) Is it true that $\displaystyle \lim_{\epsilon \to 0}\int_{-\epsilon}^{\epsilon}\cot\left(u\right)\ln\left(\sin^{2}\left(u\right)\right)du = 0$?
I understand that might seem like a silly question given the fact that most of my answers on this website are integration-related, so one would think I would find that question trivial. I understand the Cauchy Principal Value of $\displaystyle \int_{-\epsilon}^{\epsilon}\cot\left(u\right)\ln\left(\sin^{2}\left(u\right)\right)du$ equals $0$, but here, it seems like I am taking the limit of it instead. In the case of Riemann integration (i.e. $f$ is bounded), I know $\displaystyle \int_{-a}^{a}f(x)dx = 0$ is valid for integrable functions, at least when motivated by the interpretation of integration as area, for $f(a)$ being defined. (Might be irrelevant, but this is what WA says.) Still, I don't know if the same applies in my case.
I want to say my attempt is flawed. In general, the integral $\displaystyle \int_a^b f(x)dx$ is defined when $[a,b]$ lives in the domain of the definition of $f$. If so, it is $0$ when $a=b$. But for any $\epsilon > 0$, obviously $0 \in [-\epsilon, \epsilon]$, and $\cot\left(0\right)\ln\left(\sin^{2}\left(0\right)\right)$ is undefined.
For context, my background in analysis consists of an undergraduate, upper-division real analysis course, and a complex analysis course. If I missed anything trivial, please let me know. Any comment/answer shedding some light is appreciated.
 A: $\newcommand{\d}{\,\mathrm{d}}$You could only reasonably expect that integral to vanish if it had no singularities. But it has a very bad one!
Near zero we can write: $$\cot(z)=z^{-1}+z+o(z^2)$$And on this contour (I find $\int_{-\epsilon}^{\epsilon}$ to be very misleading notation, by the way) we have: $$\sin^2(\epsilon e^{i\theta})=\frac{1}{2}-\frac{1}{2}[\cos(2\epsilon\cos(\theta))\cosh(2\epsilon\sin(\theta))-i\sin(2\epsilon\cos(\theta))\sinh(2\epsilon\sin(\theta))]$$The principal logarithm of which is equal to: $$r(\theta)+i\underset{\alpha(\theta)}{\underbrace{\arctan\left(\frac{\sin(2\epsilon\cos\theta)\sinh(2\epsilon\sin\theta)}{1-\cos(2\epsilon\cos\theta)\cosh(2\epsilon\sin\theta)}\right)}}$$For small $\epsilon>0$. It is important to observe that $r(\theta)=r(\pi-\theta),\alpha(\theta)=-\alpha(\pi-\theta)$.
Let's write: $$\oint\cot(u)\ln(\sin^2(u))\d u=\oint(\cot(u)-u^{-1})\ln(\sin^2(u))\d u+\oint u^{-1}\ln(\sin^2(u))\d u$$The first integral vanishes by the ML lemma, as $(u+o(u^2))\ln(\sin^2(u))\to0$ as $u\to0$. In the second, let's write the integrand as: $$\epsilon^{-1}(\cos\theta-i\sin\theta)(r(\theta)+i\alpha(\theta))=\epsilon^{-1}[\cos(\theta)r(\theta)+\sin(\theta)\alpha(\theta)]\\+i\epsilon^{-1}[\alpha(\theta)\cos(\theta)-\sin(\theta)r(\theta)]$$Due to the aforementioned symmetries, the integral of the real part is always zero over $0\le\theta\le\pi$. However, the imaginary part is stable under $\theta\mapsto\pi-\theta$. We have that $\alpha$ tends to a constant as $\epsilon\to0$ and $r$ blows up to negative infinity. Coupled with a factor of $\epsilon^{-1}$ for good measure, it is clear that the integral of the imaginary part diverges. The imaginary part can be seen to be always positive (for small enough $\epsilon$) and if you fix any inset of choice, $0<\delta\le\theta\le\pi-\delta<\pi$, the integrand can be uniformly bounded below by a divergent quantity (namely, its value at $\delta$).

I haven't, and don't have the time to, check what's wrong with your approach. However, I recommend being veeeeery careful to ensure $\ln(\cos^2)$ is actually analytic on the contours you integrate over.
Update: $\ln(\cos^2)$ has a branch cut on $\cos^{-1}(i\Bbb R$). $\cos(z)$ is on the imaginary axis iff. $\Re z=\frac{\pi}{2}$, and you cross such a branch point (which invalidates the Cauchy residue theorem) on your path $\pi+ib\to ib$. You’re scuppered actually: no there is no way to go from $\pi$ back to $0$ without crossing $\{z:\Re z=\pi/2\}$. This approach won’t work with a principal logarithm. I suspect it fails regardless of which logarithm you take.
