Log file name formats

I’ve used several different webhosts over the years, and occasionally been frustrated by their useless, or even bizarre naming schemes for log files.

Currently I am using both 1and1.com and HostRocket. Both are fine hosts and I am quite happy with both. Except for how they handle log files.

HostRocket required me to write a script to put a copy of the log in my directory, because HostRocket clears and restarts them every day. Bizzare, but with the script it works out ok. Every so often I fire up FileZilla, download the accumulated log files, then delete them from the server. I’ve even been able to add my own log file naming scheme into the script, so it works out to be almost a positive experience in the end.

1and1 is a little more sensible. They put the log files in my directory, but the names look like this:

access.log.21.gz
access.log.22.gz
access.log.23.gz


Easy enough to download, but what about processing after? Ok, un-gzip the log files and now you have extensions like “.23” and “.24”. Additionally the file names tell you nothing about the content. What time range do the files cover? What account or domain were they associated with? I can’t delete the files from the server so I often find I’m downloading the same files I downloaded last week The log files will vanish on their own and if I’m not dilligent about downloading them they are gone forever.

A more sensible scheme would include the end date in the file name; year, month then, day. This allows the files to automatically sort by date in a typical directory listing. The file should also include the account # or domain name to help users with multiple accounts and end with the extension “.log” . Include the service the log file is for, web, mail, ftp. Gzip the files and you’re done. If the log files are regularly rotated on a specific day, users (and scripts) can already figure out file names ahead of time.

[account#].[service].[YYYY].[mm].[dd].log.gz
99999999.web.2004.12.09.log.gz
99999999.web.2004.12.30.log.gz
99999999.mail.2004.12.09.log.gz
99999999.mail.2004.12.30.log.gz
99999999.ftp.2004.12.09.log.gz
99999999.ftp.2004.12.30.log.gz

or

[domain].[service].[YYYY].[mm].[dd].log.gz
example.com.web.2004.12.09.log.gz
example.com.mail.2004.12.09.log.gz
example.com.ftp.2004.12.09.log.gz

These files automatically sort themselves and group according to domain, service, and date.