refactor logging function for readability