refactoring incoming and outgoing logging to middleware