refactor complex conditional operator usage into macro; fix logging macro bugs