refactoring of agent logging