libdlogutil: extract a common check to a function