QueryBuilder: log queries only if needed