Add debug logging to middleware