Refactored common logging code.