Proving $\int_0^\infty\frac{\mathrm dw}{(n+w)(\pi^2+(\log w)^2)}=\frac1{\log n}-\frac1{n-1}$ for any positive integer $n\geq 2$ 
For any positive integer $n\geq 2$ prove that$$\int_0^\infty\frac{\mathrm dw}{(n+w)(\pi^2+(\log w)^2)}=\frac1{\log n}-\frac1{n-1}.$$

Wolfram Alpha unfortunately cannot give a step-by-step solution (it does not even give me the form on the above RHS even if I set $n=10$, say, but comparing first few decimal digits shows that the result is almost surely correct). The only idea I had was $w=\mathrm e^{\pi\tan \theta}$ in order to kill the second multiplier of the denominator, but then I cannot deal with
$$\frac{1}{\pi}\int_{-\pi/2}^{\pi/2}\frac{\exp(\pi\tan \theta)}{(n+\exp(\pi\tan \theta))}\,\mathrm d\theta.$$
Any help appreciated!
UPDATE: Letting $w=\mathrm e^z$ and then using the residue theorem on $\displaystyle \int_{-\infty}^{\infty} \frac{\mathrm dz}{(n\mathrm e^{-z}+1)(\pi^2 + z^2)}$ with the semicircular contour centered at $0$ and radius $R$ (in the upper-half plane) seems to be a very promising idea, but unfortunately the contribution from the circular part does not tend to $0$ as $R\to \infty$. :(
 A: $\def\C{\mathbb{C}}\def\d{\mathrm{d}}\def\e{\mathrm{e}}\def\i{\mathrm{i}}\def\R{\mathbb{R}}\def\peq{\mathrel{\phantom{=}}{}}\DeclareMathOperator{\Im}{Im}\DeclareMathOperator{\Re}{Re}\DeclareMathOperator{\Res}{Res}$A general proposition can be proved by contour integration:

Proposition: Suppose that $f: \C → \C$ is a rational function with poles $z_1, \cdots, z_n \in \C \setminus \R_{\geqslant 0}$, all of which are simple. If $f(∞) = 0$ and $f(-1) ≠ 0$, then$$
\int_0^{+∞} \frac{f(x)}{(\ln x)^2 + π^2} \,\d x = \sum_{k = 0}^n \Res\left( \frac{f(z)}{\ln z - π\i}, z_k \right),
$$
  where $z_0 = -1$, $\ln z = \ln|z| + \i \arg z$, $\arg z \in (0, 2π)$.

Proof: There exists $g \in \C[z]$ such that $f(z) = \dfrac{g(z)}{\prod\limits_{k = 1}^n (z - z_k)}$, and $f(∞) = 0$ implies that $\deg g \leqslant n - 1$ and $f(z) = O\left( \dfrac{1}{z} \right)$ as $z → ∞$.
Define $h(z) = \dfrac{f(z)}{\ln z - π\i}$ for $z \in \C \setminus \R_{\geqslant 0}$. For $R > \max\limits_{0 \leqslant k \leqslant n} |z_k|$, define the (counterclockwise-oriented) contour $γ_R = γ_{1, R} \cup γ_{2, R} \cup γ_{3, R}$, where$$
γ_{1, R} = \{t \mid 0 \leqslant t \leqslant R\},\ γ_{2, R} = \{R \e^{\i t} \mid 0 < t < 2π\},\ γ_{3, R} = \{t \mid R \geqslant t \geqslant 0\}.
$$
Note that for $x \in \R_+$,$$
\lim_{\substack{z → x\\\Im z > 0}} h(z) = \frac{f(x)}{\ln x - π\i},\quad \lim_{\substack{z → x\\\Im z < 0}} h(z) = \frac{f(x)}{\ln x + π\i},
$$
thus\begin{align*}
&\peq \int_{γ_R} h(z) \,\d z = \int_{γ_{R_1}} h(z) \,\d z + \int_{γ_{R_2}} h(z) \,\d z + \int_{γ_{R_3}} h(z) \,\d z\\
&= \int_0^R \frac{f(x)}{\ln x - π\i} \,\d x + \int_{γ_{R_2}} h(z) \,\d z + \int_R^0 \frac{f(x)}{\ln x + π\i} \,\d x\\
&= \int_0^R \frac{f(x)}{\ln x - π\i} \,\d x - \int_0^R \frac{f(x)}{\ln x + π\i} \,\d x + \int_{γ_{R_2}} h(z) \,\d z\\
&= 2π\i \int_0^R \frac{f(x)}{(\ln x)^2 + π^2} \,\d x + \int_{γ_{R_2}} h(z) \,\d z.
\end{align*}
Since the poles of $h$ are $z_0, \cdots, z_n$ and are all simple, by Cauchy's integral formula,$$
\int_{γ_R} h(z) \,\d z = 2π\i \sum_{k = 0}^n \Res(h, z_k).
$$
Because $|h(z)| = \dfrac{|f(z)|}{|\ln z - π\i|} \leqslant \dfrac{|f(z)|}{\ln|z|}$, so$$
\left| \int_{γ_{R_2}} h(z) \,\d z \right| \leqslant \int_{γ_{R_2}} |h(z)| \,\d z \leqslant 2πR \max_{|z| = R} |h(z)| \leqslant \frac{2πR}{\ln R} \max_{|z| = R} |f(z)|,
$$
combining with $f(z) = O\left( \dfrac{1}{z} \right)$ ($z → ∞$) yields $\displaystyle \lim_{R → +∞} \int_{γ_{R_2}} h(z) \,\d z = 0$. Therefore,\begin{gather*}
2π\i \sum_{k = 0}^n \Res(h, z_k) = \lim_{R → +∞} \int_{γ_R} h(z) \,\d z\\
= 2π\i \lim_{R → +∞} \int_0^R \frac{f(x)}{(\ln x)^2 + π^2} \,\d x + \lim_{R → +∞} \int_{γ_{R_2}} h(z) \,\d z = 2π\i \int_0^{+∞} \frac{f(x)}{(\ln x)^2 + π^2} \,\d x,
\end{gather*}
which implies\begin{gather*}
\int_0^{+∞} \frac{f(x)}{(\ln x)^2 + π^2} \,\d x = \sum_{k = 0}^n \Res(h, z_k) = \sum_{k = 0}^n \Res\left( \frac{f(z)}{\ln z - π\i}, z_k \right). \tag*{$\square$}
\end{gather*}
Now return to the question. For $n > 0$ with $n ≠ 1$, by the proposition,\begin{gather*}
\int_0^{+∞} \frac{1}{(n + x)((\ln x)^2 + π^2)} \,\d x\\
= \Res\left( \frac{1}{(n + z)(\ln z - π\i)}, -1 \right) + \Res\left( \frac{1}{(n + z)(\ln z - π\i)}, -n \right).
\end{gather*}
Since\begin{gather*}
\Res\left( \frac{1}{(n + z)(\ln z - π\i)}, -1 \right) = \lim_{z → -1} \frac{z + 1}{(n + z)(\ln z - π\i)} = \lim_{w → π\i} \frac{\e^w + 1}{(n + \e^w)(w - π\i)}\\
= \left( \lim_{w → π\i} \frac{1}{n + \e^w} \right) \left( \lim_{w → π\i} \frac{\e^w + 1}{w - π\i} \right) = \frac{1}{n - 1} · (\e^w)'\bigr|_{w = π\i} = -\frac{1}{n - 1},
\end{gather*}$$
\Res\left( \frac{1}{(n + z)(\ln z - π\i)}, -n \right) = \lim_{z → -n} \frac{z + n}{(n + z)(\ln z - π\i)} = \frac{1}{\ln(-n) - π\i} = \frac{1}{\ln n},
$$
then$$
\int_0^{+∞} \frac{1}{(n + x)((\ln x)^2 + π^2)} \,\d x = \frac{1}{\ln n} - \frac{1}{n - 1}.
$$
A: The purpose of this answer is to show the limits of the residue method for computing real integrals.  The first question I asked myself when seeing this integral is "why is the $\pi^2$ there?"  This answer resolves that question by showing that the residue method for evaluating real integrals only works when the
term in the denominator is $\log^2(x) + k^2$ for $k=m\pi$ for some positive integer $m$.

Consider the integral
$$
  I(a,k) = \int_0^{\infty} \frac{dx}{(x+a)(\log^2 x + k^2)}
$$
for $a\ge 0$ and $k>0$ (note that this uses $a$ instead of $n$ and the more general $k$ instead of $\pi$).

The special case $I(0,k)$ is easy to compute since the integrand has a closed-form antiderivative in this case:
$$
  I(0,k) = \int_0^{\infty} \frac{dx}{x (\log^2(x) + k^2)} = \left.\frac{1}{k} \arctan(\log(x)/k)\right|_0^{\infty}
         = \frac{\pi}{k}.
$$


The special case $I(1,k)$ is also fairly easy to compute.  First use the substitution $u=1/x$ 
(as suggested at the AoPS link in Zacky's comment):
$$
  I(1,k) = \int_0^{\infty} \frac{dx}{(x+1)(\log^2(x) + k^2)} 
         = \int_0^{\infty} \frac{du}{u(u+1)(\log^2(u) + k^2)}.
$$
Note that 
$$
\frac{1}{u(u+1)} = \frac{1}{u} - \frac{1}{u+1}.
$$
So $I(1,k) = \pi/k - I(1,k)$.  This means 
$$
I(1,k) = \frac{\pi}{2k}.
$$


For general $a \ge 0$, we can try to use the residue theorem.  First use the substitution $u=\log x$ to get
$$
  I(a,k) = \int_{-\infty}^{\infty} \frac{e^u}{(e^u + a)(u^2 + k^2)} du.
$$

Now define
$$
  f(z) = \frac{e^z}{(e^z+a)(z - ki)}.
$$
Let $\gamma$ be the boundary of the rectangle with vertices at the points $-R$, $R$, $R+2n\pi i$, and 
$-R+2n\pi i$ in the complex plane with $n$ some positive integer.  
This is the same $f(z)$ and similar $\gamma$ to those used in the answer linked in Zacky's comment.
Let the parameterizations of the edges
of the rectangle (starting with the bottom edge and moving counter-clockwise) be $x(t)+y(t)i = t$ 
(for $-R\le t \le R$), $x(t)+y(t)i = R+ti$ (for $0\le t\le 2n\pi$), 
$x(t)+y(t)i = t+2n\pi i$ (for $R\ge t \ge -R$), and $x(t)+y(t)i = -R+ti$ (for $2n\pi \ge t \ge 0$).
Then the contour integral of $f(z)$ around the curve $\gamma$ is
$$
  \begin{align}
  \int_{\gamma} f(z) dz &= \int_{-R}^{R} \frac{e^t}{(e^t+a)(t-ki)} dt \\
                             & \quad + \int_0^{2n\pi} \frac{i\exp(R+ti)}{(\exp(R+ti)+a)(R+ti-ki)} dt \\
                             & \quad + \int_R^{-R} \frac{\exp(t+2n\pi i)}
                                       {(\exp(t+2n\pi i) + a) (t + (2n\pi -k)i)} dt \\
                             & \quad + \int_{2n\pi}^{0} \frac{i \exp(-R+ti) dt}
                                       {(\exp(-R+ti) + a)(-R+ti-ki)}.
  \end{align}
$$
The two portions along the vertical edges vanish as $R\rightarrow\infty$.  If we let $k=n\pi$ (and only if we let $k=n\pi$), then the two portions along the horizontal edges combine into
$$
  \int_{-R}^R \frac{e^t}{e^t+a}\left(\frac{1}{t-ki} - \frac{1}{t+ki}\right) dt
  = 2\pi ni \int_{-R}^R \frac{e^t}{(e^t+a)(t^2+k^2)} dt. \tag{1}\label{contour_integral}
$$
The limit of the integral in the right-hand side of\eqref{contour_integral} as $R\rightarrow\infty$ is 
$I(a,k)$.  So by the residue theorem,
$$
  I(a,n\pi) = \frac{1}{n} \sum_{j} \textrm{Res}(f,c_j)
$$
where the $c_j$ are the poles of $f(z)$ inside $\gamma$.  The poles of $f$ inside $\gamma$ are
the points where $z=ki=n\pi i$ and $e^z+a=0$.  So $c_0 = n\pi i$ and $c_j = \log a + i\pi + 2\pi (j-1)i$
for $j=1,2,\dots, n$.  All poles are simple, meaning the residues can all be computed using 
$\lim_{z\rightarrow c_j} f(z)(z-c_j)$.  Using this method,
$$
  \textrm{Res}(f,c_0) = \frac{e^{n\pi i}}{e^{n\pi i}+a} = \frac{(-1)^n}{(-1)^n + a}
$$
and 
$$
  \textrm{Res}(f,c_j) = \frac{1}{\log a + \pi i(1+2(j-1) - n)} \quad \textrm{for} \ j=1,2,\dots n.
$$
In the sum of the residues for $j=1,2,\dots n$, the imaginary part is 0.  The real part is
$$
  \sum_{j=1}^n \textrm{Res}(f,c_j) = \sum_{j=1}^n \frac{\log a}{\log^2 a + \pi^2(1 + 2(j-1) - n)^2}.
$$

So
$$
  I(a,n\pi) = \frac{1}{n}\left(\frac{(-1)^n}{(-1)^n + a} + 
              \sum_{j=1}^n \frac{\log a}{\log^2 a + \pi^2(1 + 2(j-1) - n)^2} \right).
$$
For $n=1$, this is $-1/(a-1) + 1/\log a$.


So the residue method for computing the integral works, but only for $k=n\pi$.  For all other values of $k$, assuming $a\ne 0$ and $a\ne 1$, numerical integration is necessary.  The form of the integral
$$
  I(a,k) = \frac{1}{k} \int_{-\pi/2}^{\pi/2} \frac{\exp(k \tan\theta)}{\exp(k\tan\theta) + a} d\theta
$$
is better for numerical integration since the domain is finite.  This can be split into two integrals to
keep the argument of the exponential function below positive infinity:
$$
  I(a,k) = \frac{1}{k}\int_{-\pi/2}^0 \frac{\exp(k \tan\theta)}{\exp(k\tan\theta) + a} d\theta +
           \frac{1}{k}\int_0^{\pi/2} \frac{d\theta}{1 + a\exp(-k\tan\theta)}. \tag{2}\label{sum_of_integrals}
$$
Gauss quadrature produces a very fast and accurate answer using \eqref{sum_of_integrals}.  It does not
matter that $\tan\theta$ is infinite at the interval endpoints since Gauss quadrature does not evaluate the function at the interval endpoints.

