About the proof that $\int_0^\infty\frac{dx}{x^2+6x+8} =\frac12\log2$ via residue formula
Solution 1:
First of all, in your proposition, since $x$ is a dummy variable, it makes no sense to say '$\text{for all }x\in\mathbb R$'.
Besides, it is not quite clear how you obtained $(***)$.
Here, I provide a lemma, which can be applied to derive $(***)$, as well as explaining the motivation to introduce $\log(z)$ at the first place.
Lemma
$$\lim_{\Delta\to0^+}\left(\int_{\gamma_1}+\int_{\gamma_2}\right)f(z)\ln(z-s)dz=-2\pi i\int_{pe^{i\theta}}^{qe^{i\theta}}f(t)dt$$
Proof:
Let $\hat{k}=i\frac{s}{|s|}$
\begin{align*} &~~~~\lim_{\Delta\to0^+}\left(\int_{\gamma_1}+\int_{\gamma_2}\right)f(z)\ln(z-s)dz \\ &=\lim_{\Delta\to0^+}\left(\int_{\gamma_1}+\int_{\gamma_2}\right)f(z)\ln|z-s|dz +i\lim_{\Delta\to0^+}\left(\int_{\gamma_1}+\int_{\gamma_2}\right)f(z)\arg(z-s)dz \\ &=\left(\int_{pe^{i\theta}}^{qe^{i\theta}}+\int^{pe^{i\theta}}_{qe^{i\theta}}\right)f(z)\ln|z-s|dz \\ &~~~~+i\lim_{\Delta\to0^+}\int^{qe^{i\theta}+\Delta\hat{k}}_{pe^{i\theta}+\Delta\hat{k}} f(z)\arg(z-s)dz +i\lim_{\Delta\to0^+}\int^{qe^{i\theta}-\Delta\hat{k}}_{pe^{i\theta}-\Delta\hat{k}} f(z)\arg(z-s)dz\\ \end{align*}
Obviously the first term is zero.
For the second term, by the substitution $z=ue^{i\theta}+\Delta\hat{k}$ \begin{align*} &~~~~ i\lim_{\Delta\to0^+}\int^{qe^{i\theta}+\Delta\hat{k}}_{pe^{i\theta}+\Delta\hat{k}} f(z)\arg(z-s)dz \\ &=i\lim_{\Delta\to0^+}\int^q_p f(ue^{i\theta}+\Delta\hat{k})\arg(ue^{i\theta}+\Delta\hat{k}-s)e^{i\theta}du \\ &=i\int^q_p f(ue^{i\theta})\theta e^{i\theta}du \\ &=i\theta\int_{pe^{i\theta}}^{qe^{i\theta}}f(t)dt \end{align*}
From the second line to the third line, dominated convergence theorem is applied to exchange limit and integral, and $\lim_{\Delta\to 0^+}\arg(ue^{i\theta}+\Delta\hat{k}-s)=\theta$ is used.
For the third term, by the substitution $z=ue^{i\theta}-\Delta\hat{k}$ \begin{align*} &~~~~ i\lim_{\Delta\to0^+}\int_{qe^{i\theta}-\Delta\hat{k}}^{pe^{i\theta}-\Delta\hat{k}} f(z)\arg(z-s)dz \\ &=i\lim_{\Delta\to0^+}\int_q^p f(ue^{i\theta}-\Delta\hat{k})\arg(ue^{i\theta}-\Delta\hat{k}-s)e^{i\theta}du \\ &=-i\int^q_p f(ue^{i\theta})(2\pi+\theta) e^{i\theta}du \\ &=-i(2\pi+\theta)\int_{pe^{i\theta}}^{qe^{i\theta}}f(t)dt \end{align*}
Similarly, $\lim_{\Delta\to 0^+}\arg(ue^{i\theta}-\Delta\hat{k}-s)=2\pi+\theta$ is used.
As a result, \begin{align*} &~~~~\lim_{\Delta\to0^+}\left(\int_{\gamma_1}+\int_{\gamma_2}\right)f(z)\ln(z-s)dz \\ &=0+i\theta\int_{pe^{i\theta}}^{qe^{i\theta}}f(t)dt-i(2\pi+\theta)\int_{pe^{i\theta}}^{qe^{i\theta}}f(t)dt\\ &=-2\pi i\int_{pe^{i\theta}}^{qe^{i\theta}}f(t)dt \end{align*}
Q.E.D.