Added finer-grained logging control.

See commits for comments.