Reorganize buildLogFunction to make logic a bit clearer.  No functional
changes.
Move Tracer into separate file, as arguably not core (and not guaranteed to
work in current incarnation).