Refactoring the Logging Logic