log: logging debug only when flag is set to true