python loggin handler to log debug info only if an error occured