remade the entire logger to handle middleware