Hey guys,
I'm currently busy with a log program, that writes some information into a txt file and that should write every 5 minutes, the date and the time. But now I have a problem with the logging the date and time while I'm also logging the information. Well, in my loop I need two "sleep()" statements, but I only can use one, Here's a lil' example what I'm meaning. Look at the code below, it shows a code, that write every loop "poop" into a txt file. But at the same time, I need a timer that record the time for the date info that also should be logged every 5 minutes.
Summary: I want a loop that every 5 minutes writes the date and time into a txt file. But I want to write in that 5 minutes every minute some other info writed down. How can i do this?
This is really best done using separate threads or processes. Create a thread-safe queue onto which log messages are written. Have a thread that does nothing by reads messages from the queue and writes them to a file. Then have a thread that loops: sleep for 5 minutes, write a timestamp to the queue. Your main thread can write whatever it wants to the queue and have it go to the log file.