  Let $(\Sigma, g)$ be a compact Riemannian surface. Let $\psi$, $h$ be two
smooth functions on $\Sigma$ with $\int_\Sigma \psi dv_g \neq 0$ and $h\geq0$,
$h\not\equiv0$. In this paper, using a method of blowup analysis, we prove that
the functional \begin{align}\label{functional_J}
  J^{\psi,h}(u)=\frac{1}{2}\int _{\Sigma}|\nabla_g u|^2dv_g +
8\pi\frac{1}{\int_\Sigma \psi dv_g}\int_\Sigma \psi udv_g-8\pi\log\int
_{\Sigma}he^{u}dv_g \end{align} is bounded from below in $W^{1,2}(\Sigma,g)$.
Moreover, we obtain a sufficient condition under which $J^{\psi, h}$ attains
its infimum in $W^{1,2}(\Sigma,g)$. These results generalize the main results
in \cite{DJLW97} and \cite{YZ2016}.
