I think, you should define log() function before the custom handler class.
log()
You can define it like this,
def log(mensagem): print(mensagem)