Refactored message logging