Add docstrings and fix lint warnings.  Factor out log setting code into
its own module as this is used by several tools and could do with being
shared.