Set up the logging system and improve middleware