Evaluate $\int_0^{\infty } \Bigl( 2qe^{-x}-\frac{\sinh (q x)}{\sinh \left(\frac{x}{2}\right)} \Bigr) \frac{dx}x$

The formula of the question follows easily from Ramanujan's generalization of Frullani's integral. See 'The Quarterly Reports of S. Ramanujan,' American Mathematical Monthly, Vol. 90, #8 Oct 1983, p 505-516. I won't give the conditions, but state it to establish the notation. Let $$ f(x)-f(\infty)=\sum_{k=0}^\infty u(k)(-x)^k/k! \quad,\quad g(x)-g(\infty)=\sum_{k=0}^\infty v(k)(-x)^k/k!$$ $$ f(0)=g(0) \quad,\quad f(\infty)=g(\infty) $$ Then $$\int_0^\infty \frac{dx}{x} \big(f(ax) - g(bx) \big)= \big(f(0)-f(\infty) \big)\Big( \log{(b/a)} + \frac{d}{ds} \log{\Big(\frac{v(s)}{u(s)}\Big)}\Big|_{s=0} \Big) $$ For the OP's case, a=b=1, $f(x)=2qe^{-x} \implies u(k)=2q, \ f(0)=2q, f(\infty)=0.$ We will eventually show $$ (1) \quad g(x)=\frac{\sinh(q \ x)}{\sinh(x/2)} = -\sum_{n=0}^\infty \frac{(-x)^n}{n!} \ \cos(\pi \ n) \big( \zeta(-n, 1/2+q) - \zeta(-n, 1/2-q) \big)$$ where $\zeta(s,a)$ is the Hurwitz zeta function. Given (1), it is easy to see that $$ \frac{d}{ds} \log{v(s)} \big|_{s=0} = \frac{v'(0)}{v(0)} = -\frac{ \zeta'(0, 1/2+q)-\zeta'(0, 1/2-q)}{ \zeta(0, 1/2+q)-\zeta(0, 1/2-q) }$$ However, it is known that $$\zeta'(0,a)=\log(\Gamma(a)/\sqrt{2\pi}) \text{ and } \zeta(0,a)=-B_1(a)=1/2-a $$ where in the last formula the Hurwitz zeta has been connected to the Bernoulli polynomial by the formula $$ (2) \quad \zeta(-n,a) = -\frac{B_{n+1}(a)}{n+1}. $$ Doing the rest of the algebra results in the expression $$ (3) \quad \int_0^\infty \Big(2qe^{-x} - \frac{ \sinh(q \ x)}{\sinh{x/2} } \Big) \frac{dx}{x} = \log{\Gamma(1/2+q)} - \log{\Gamma(1/2-q)}. $$ To get it in the form of the OP's request, use the gamma-function reflection formula

$$ \Gamma(1/2-q)\Gamma(1/2+q) = \frac{\pi}{\cos{\pi q } } .$$

Now, to prove (1): $$ \frac{\sinh(q \ x)}{\sinh(x/2)} = \frac{e^{qx} - q^{-qx}}{e^{x/2}-e^{-x/2}} = \frac{1}{x}\Big( \frac{x}{e^x-1} \exp(x(1/2+q))+\frac{x}{e^x-1} \exp(x(1/2-q)) \Big) $$ Use the well-known generating function for Bernoulli polynomials, $$ \frac{\sinh(q \ x)}{\sinh(x/2)} =\frac{1}{x}\sum_{n=0}^\infty \frac{x^n}{n!} \Big( B_n(1/2+q) - B_n(1/2-q) \Big) =\sum_{n=0}^\infty \frac{x^n}{n!(n+1)} \Big( B_{n+1}(1/2+q) - B_{n+1}(1/2-q) \Big) $$ where in the second step we have re-indexed because $B_0(x)=1$ and the first term is thus zero. Then use (2) in the last formula to complete the proof of (1).


$\newcommand{\bbx}[1]{\,\bbox[15px,border:1px groove navy]{\displaystyle{#1}}\,} \newcommand{\braces}[1]{\left\lbrace\,{#1}\,\right\rbrace} \newcommand{\bracks}[1]{\left\lbrack\,{#1}\,\right\rbrack} \newcommand{\dd}{\mathrm{d}} \newcommand{\ds}[1]{\displaystyle{#1}} \newcommand{\expo}[1]{\,\mathrm{e}^{#1}\,} \newcommand{\ic}{\mathrm{i}} \newcommand{\mc}[1]{\mathcal{#1}} \newcommand{\mrm}[1]{\mathrm{#1}} \newcommand{\pars}[1]{\left(\,{#1}\,\right)} \newcommand{\partiald}[3][]{\frac{\partial^{#1} #2}{\partial #3^{#1}}} \newcommand{\root}[2][]{\,\sqrt[#1]{\,{#2}\,}\,} \newcommand{\totald}[3][]{\frac{\mathrm{d}^{#1} #2}{\mathrm{d} #3^{#1}}} \newcommand{\verts}[1]{\left\vert\,{#1}\,\right\vert}$ With $\ds{q \in \mathbb{R}}$, note that \begin{align} &\bbox[10px,#ffd]{\left.\int_{0}^{\infty}{1 \over x}\bracks{2q\expo{-x} - {\sinh\pars{qx} \over \sinh\pars{x/2}}}\dd x \,\right\vert_{{\large q\ \in\ \mathbb{R}} \atop {\large q^{2}\ <\ 1/4}}} \\[5mm] = &\ \left.\mrm{sgn}\pars{q}\int_{0}^{\infty}{1 \over x} \bracks{2\verts{q}\expo{-x} - {\sinh\pars{\verts{q}x} \over \sinh\pars{x/2}}}\dd x \,\right\vert_{\ \verts{q}\ <\ 1/2} \label{1}\tag{1} \end{align} The last integral becomes: \begin{align} &\!\!\!\!\!\!\!\!\!\!\bbox[10px,#ffd]{\int_{0}^{\infty}{1 \over x}\bracks{2\verts{q}\expo{-x} - {\expo{-\pars{1/2 - \verts{q}}x} - \expo{-\pars{1/2 + \verts{q}}x} \over 1 - \expo{-x}}}\dd x} \\[5mm] \stackrel{x\ =\ -\ln\pars{t}}{=} &\ \int_{1}^{0}{1 \over -\ln\pars{t}}\pars{2\verts{q}t - {t^{1/2 - \verts{q}} - t^{1/2 + \verts{q}} \over 1 - t}} \pars{-\,{\dd t \over t}} \\[5mm] = &\ \!\!\!\! \int_{0}^{1}\!\!\underbrace{\bracks{-\,{1 \over \ln\pars{t}}}} _{\ds{\int_{1}^{\infty}t^{\xi - 1}\,\dd\xi}} {2\verts{q} - 2\verts{q}t - t^{-1/2 - \verts{q}} + t^{-1/2 + \verts{q}} \over 1 - t}\, \dd t \\[5mm] = &\!\!\! \int_{1}^{\infty}\!\!\!\!\int_{0}^{1}\!\! {2\verts{q}t^{\xi - 1} - 2\verts{q}t^{\xi} - t^{\xi - 3/2 - \verts{q}} + t^{\xi - 3/2 + \verts{q}} \over 1 - t}\,\dd t\,\dd\xi \\[5mm] = &\ \int_{1}^{\infty}\int_{0}^{1}\left[% 2\verts{q}\int_{0}^{1}{1 - t^{\xi} \over 1 - t}\,\dd t - 2\verts{q}\int_{0}^{1}{1 - t^{\xi - 1} \over 1 - t}\,\dd t\right. \\[2mm] &\ \left. +\int_{0}^{1}{1 - t^{\xi - 3/2 - \verts{q}} \over 1 - t}\,\dd t - \int_{0}^{1}{1 - t^{\xi - 3/2 + \verts{q}} \over 1 - t}\,\dd t \right]\dd\xi \\[5mm] = &\ \int_{1}^{\infty}\left[\vphantom{\huge A}\,% 2\verts{q}\Psi\pars{\xi + 1} - 2\verts{q}\Psi\pars{\xi}\right. \\[2mm] & \phantom{\int_{1}^{\infty}\left[\right.} \left. +\ \Psi\pars{\xi - {1 \over 2} - \verts{q}} - \Psi\pars{\xi - {1 \over 2} + \verts{q}}\right]\dd\xi \label{2}\tag{2} \\[5mm] = & \overbrace{\lim_{\xi \to \infty}\bracks{ 2\verts{q}\ln\pars{\xi} + \ln\pars{\Gamma\pars{\xi - 1/2 - \verts{q}} \over \Gamma\pars{\xi - 1/2 + \verts{q}}}}} ^{\ds{=\ 0}} \\[2mm] &\ +\ln\pars{\Gamma\pars{1/2 + \verts{q}} \over \Gamma\pars{1/2 - \verts{q}}} \\[5mm] = &\ \ln\pars{\Gamma^{\, 2}\pars{1/2 + \verts{q}} \over \Gamma\pars{1/2 + \verts{q}}\Gamma\pars{1/2 - \verts{q}}} \\[5mm] = &\ \ln\pars{\Gamma^{\, 2}\pars{1/2 + \verts{q}} \over \pi/\sin\pars{\pi\bracks{1/2 + q}}}\label{3}\tag{3} \\[5mm] = &\ \bbx{\ln\pars{\cos\pars{\pi\verts{q}}} + 2\ln\pars{\Gamma\pars{\verts{q} + {1 \over 2}}} - \ln\pars{\pi}}\label{4}\tag{4} \\ & \end{align} (\ref{2}): I used an integral representation ( see $\ds{\color{black}{\bf 6.3.22}}$ in A & S Table ) of the digamma $\ds{\mbox{function}\ \Psi}$.

(\ref{3}): Euler Reflection Formula. See $\ds{\color{black}{\bf 6.1.17}}$ in A & S Table.


Finally, with (\ref{1}) and (\ref{4}): \begin{align} &\bbox[10px,#ffd]{\left.\int_{0}^{\infty}{1 \over x}\bracks{2q\expo{-x} - {\sinh\pars{qx} \over \sinh\pars{x/2}}}\dd x \,\right\vert_{{\large q\ \in\ \mathbb{R}} \atop {\large q^{2}\ <\ 1/4}}} \\[5mm] = &\ \bbox[25px,#ffd,border:1px groove navy]{\mrm{sgn}\pars{q}\bracks{\ln\pars{\cos\pars{\pi\verts{q}}} + 2\ln\pars{\Gamma\pars{\verts{q} + {1 \over 2}}} - \ln\pars{\pi}}} \\ &\ \end{align}