Fix bug: logs were always sent in "error" because of a block versus function scope