Logging api

Refactorings to support testing logging interface. @bernerdschaefer @peterbourgon 
This function only has 1 caller. Probably should just be inlined.