Tracking Usage and writing to a file in hugging space


I built a program that is using GPT to generate a certain ouput. I am sharing this program with several others in my department. My goal is calculate and track the tokens used everytime its run. I have it where it writes the token to a text file along with the date and day, but this is not working. Any idea how I can approach that? I am a little new to hugging space, so please excuse my lack of knowledge,