avoid possible loops in exception formatter

Having a loop in __cause__ attributes should be considered a bug, but
for diagnosing it, the logger should not fail.
avoid printing duplicate tracebacks

It occasionally happened that a traceback would be given both explicitly
and attached to the __traceback__ attribute. It would then be printed
twice.