Extract log utils into pkg/log

Carry of #7222 -- all tests pass, squashed and rebased against master.

/cc @vieux @capoferro