refactoring grammar logging