My aim is to evaluate the integral $$I = \int_{-\infty}^{\infty} \frac{z\ln(1+e^z) }{(1+z^2)^2}dz = \frac{\pi}{4}$$ directly with contour integration. How can I do this? In particular, how should I handle the many branch points associated with $z=(2n+1)\pi i$ for each integer $n$?
On a naive attempt, I equated $I$ with a semi-circle contour integral of the same function in the upper half plane (the function should be decreasing in $|z|$ fast enough so that the arc won't contribute), which would pick up the residue from $z=i$. Naively, that would be $2 \pi i \frac{d}{dz} \frac{z\ln(1+e^z)}{(1+z^2)^2}$ evaluated at $z=i$, which would yield $\frac{\pi}{2(1+e^{-i})}$.
Unfortunately, there shouldn't be an imaginary part, but the real part looks ok. Normally with such occurrences, I would just drop the imaginary part and continue. However, I want to understand what's going wrong, and how to draw an appropriate contour or identify additional contributions.

Here is a completed attempt with one choice of branch cuts.
I will define $\ln(z)$ to have a branch cut on the positive real axis.
Given that $\ln(1+e^z)$ has branch points at $z=(2n+1)\pi i$, and $1+e^z$ has positive real part for $\Re(z)<0$ with sign of $\Im(z)$ changing as one passes through $\Im(z)=(2n+1)\pi$, then $\ln(1+e^z)$ has branch cuts going horizontally to the left from the branch points.
I will thus take the following contour:
I found the contribution from the double pole at $z=i$ in the OP, and the arc is again negligible, yielding
$$\frac{\pi}{2(1+e^{-i})}= I + \sum_{n=0}^\infty \int_{-\infty}^0 (2\pi i) \frac{x+(2n+1)\pi i}{(1+(x+(2n+1)\pi i)^2)^2}$$
The left hand-side is the contribution from the double pole, and the rightmost sum is, for a given $n$, from the rightgoing + leftgoing horizontal lines following the branch cut about the branch point at $(2n+1)\pi i$. It is straightforward to integrate, using $\int dx \frac{x}{(1+x^2)^2} = -\frac{1}{2(1+x^2)}$.
$$\frac{\pi}{2(1+e^{-i})}= I + \sum_{n=0}^\infty (2\pi i) \frac{-1}{2(1+((2n+1)\pi i)^2)}$$
Summing (via $\sum_{n=0}^\infty \frac{1}{((2n+1)\pi)^2-a^2} = \frac{\pi}{4a} \tan(\frac{ \pi a}{2})$) and rearranging, one finds
$$I = \frac{\pi}{2(1+e^{-i})}-\frac{\pi i}{4}\tan(1/2)$$
After a little trig, this simplifies to
$$I = \frac{\pi}{4}$$
which completes this problem.