Mahabharata

how Ved Vyasa wrote about the Mahabharat War

In Mahabharata

Ved Vyasa and Sanjay both were not present in the battle of Mahabharata in Kurukshetra. Then how Sanjay knew that what was happening there in the battle and how Ved Vyasa wrote about the Mahabharat War ???