Refactored command-logging to make use smaller more reusable pieces

 * I found a case in my reports code that was replicating large pieces
   of the guts of this (predating this code) and am refactoring it to
   get it all going through a common code path