Rotating Log Files

Posted on

If you're not careful with how you handle log files on your server, you may be surprised one day if it crashes because the file grows to the file size limit on your operating system. To prevent that, you'll want to implement some sort of log rotation system. On most linux distributions, this is most commonly handled by LogRotate which runs as a daily cronjob.

One minor drawback to logrotate is that you have to list explicitly which logs to rotate in its configuration files. This can be pretty tedious once Apache serving more than a handful of sites. One solution is to log all trafic to your virtual hosts to a single file, but I like each site to have its own logfiles. In the past, I had put together a quick little script that would rotate scripts for me at the begining of each month but this also requires adding a new host to the list of logs to rotate.. Since I didn't want to have to remember another step when setting up sites on my server, I decided to look for other options for rotating the apache logs on a monthly basis. I found cronolog, which is a clever little program:

cronolog is a simple filter program that reads log file entries from standard input and writes each entry to the output file specified by a filename template and the current date and time. When the expanded filename changes, the current file is closed and a new one opened.\

The program was easy to download and compile from source. Now, when setting up a virtual host, instead of using lines like the following:\

CustomLog /www/hosts/oscarm.org/logs/access.log combined

I simply use the following to get automagically rotating logs with the year and month at the beggining of the filename (note the quotes and pipe at the beginning):\

CustomLog "|/path/to/cronolog /www/hosts/oscarm.org/logs/%Y-%m.access.log" combined

On a related topic, if you are writing web applications and logging any errors or output yourself, you'd be wise to rotate logs as well and not expect your server admin to know to do it for you. In PHP, this is trivially easy using the date function when you specify what file to log to. Instead of doing:

$logfile = "/path/to/my_logfile.log"

You should do this:

$logfile = "/path/to/".date('Y-m').".my_logfile.log"

Tags: Linux

─── ✧ ─── ✦ ─── ✧ ───

MLS Changes Blog Roundup

Posted on

On the heels of the MLS Cup, both Off Wing Opinon and The Sports Economist have pieces on changes in the works for Major League Soccer discovered in this AP article: MLS Should look to Rest of World.  The article is pretty short and lacking in actual details about what changes might be in store for the league so I wouldn't jump to any conclusions. I think it's mostly an afirmation that in the first  years of the league, those in charge changed too much about the setup in an attempt to Americanize a global sport. Changes over the last few years such as counting the clock up, eliminating the shootout, and allowing regular season games to end in a tie have brought play in line with how its played in the rest of the world.\

Tags: Soccer

─── ✧ ─── ✦ ─── ✧ ───

Dale Campeon, Dale Campeon!!

Posted on

What a tense match today in LA that saw DC United walk away as MLS champions for the fourth time in nine seasons. Please don't expect a coherent narrative right now, I wanted to get some thoughts down before my sun-fried brain shuts down:

The Home Depot Center is a great little stadium and I hope to see more like it built around the league. RFK is great for atmosphere but its severely lacks in amentities. There were a ton of food stalls and lines weren't all that long at them. We were all also very impressed by how many rest rooms, and how large each one was.

The game itself was intense. Not necessarily up to the level of drama involved in last week's Eastern Conference Final, but enough to be a worthy final. Kansas City struck early and first but DC responded with three goals before the first half was over. After going down a man in the 3rd half and a second KC goal from the penalty spot, it was tense moments watching United defend its one goal lead as the clock ticked up to 90. 

Honestly, at the beginning of the season and after enduring the last 3 seasons at RFK, I didn't not conceive that DC United would be playing in the championship much less walking away with it. After the All Star game though, this team started to really click and it has been tremendously fun cheering the team during the playoffs and through today. As a sports fan, you have to relish the moments when your team is playing well and winning. We were spoiled by DC's early success, so that realization has made me relish this championship all the more.

The folks at MLS HQ must be overjoyed that phenom Freddy Adu's team made it to the final and that he made an appearance as a sub. While Freddy-mania threatened to overshadow the team at the beginning of the season, he managed to prove he belonged and found a role on the team.  Hopefully, this is a bright start to a bright career. As much as Freddy will be one of the big stories this season, there are other stories that I'll be taking away. 

First and foremost, is the re-emergence of Jaime Moreno as a player and dangerous forward. I've been a fan of his since the beginning, both for his exploits during DC United's glory years but also following him on the Bolivian national team during the late 90s. His disastrous, injury filled season last year with the Metrostars was sad to see but he really came back with something to prove this year - even if the league snubbed him by giving the MVP award to Amado Guevarra.

Also, it's good to see players like Mike Petke and Nick Rimando, who have spent their entire professional soccer careers in this League, get a championship ring. MLS is begining to show that not everyone has to go to Europe to enjoy a successful career in the sport.

Tags: Soccer

─── ✧ ─── ✦ ─── ✧ ───