Forums

Can I use the access.log file as an "visits counter"?

Hi, In my account I have a webapp where I only store some images, now my client needs a "visits counter" (something like the "Traffic"area on dashboard I think) and firstly I was thinking in create a webapp to store every request on a database and show this data on a simple html page, but I noticed that the access.log file has every request data and I want to know if it is a bad idea to use this files to get that data, if it isn't a so bad idea can you tell me details of how this file work (I readed in another thread that the file is rotated every day, but I don't know if it happens in the same hour every day for instance). Please let me know if that idea was not so good, thanks.

You could use the access log file, but (as I think you're aware) handling rotation might get tricky. The rotation doesn't happen at exactly the same time every day -- basically, we have a script that rotates everyone's logs, one person after another, and so if (for some reason) someone who happens to get processed earlier than you takes longer than normal, your own file rotation might happen later than it normally does. And to add to the potential for confusion, we only rotate logs when they're larger than 100KiB in size, so on days with little traffic, your logfile might not be rotated at all.

So I'd recommend using the DB solution if you easily can.

Hi giles, Thanks for your help, I'll proceed with the other option!

Sounds like a good plan!

anyone got a script for this? Wont we end up with huge duplicates .. same rows in log.1 from day 1 as in log.3 later etc etc

We do not have anything out of the shelf.