fixed UnboundLocalError beforeMidnight in logdb