Add a pending_event state stack and use that when storing trace data.

This is a small step towards a "real" stack of states: the state stack
here is redundant with |ctx->event|.
Tweak logging helpers to make scanning voluminous output more efficient.