This question comes up from time to time and I've yet to read a convincing explanation of what is meant by "time spent by user on the course".
Do you mean the time the
server spent generating the page for the user? (Probably a fraction of a second for each page loaded)
Do you mean the time the user had the page open in a browser? (Regardless of whether or not the user was actually looking at the page, maybe they just opened it and walked off to make a cup of tea)
Does having the course open in 2 tabs at once count double?
Should it count against them if they have tabs for 3 different courses open at once - or does it count as them being on each of those courses? (even though they can't possibly be reading all of them at once)
The closest I've seen is to parse the logs and apply some cut-off for the maximum time between two log entries for a single course (i.e. if two log entries for a user on a course are more than 15 min apart, then count them as two separate sessions on the course). This still doesn't really give any idea if the user is actually engaging with the course, or just occasionally randomly clicking on links (it also breaks if they watch a 20 minute video on the course - that might end up splitting two sessions, if they didn't do anything else at the same time).
I hope that helps, but please consider using better measures of student engagement (number of posts on forums, performance against formative / summative assessment quizzes, etc.)