Stacked Notion

How to Setup Log Rotation for Rails Apps

| Comments

I’m sure we’ve all been there. You’ve been tasked with fixing a Rails app, you go in for some debugging magic and find the production.log is 3GB and counting as nobody bothered to setup log rotation. Here is how to avoid that… On Ubuntu machines (and I would guess most other Linux distributions) logrotate comes installed by default. To set it up, you just need to create a new config file in /etc/logrotate.d/, for example:

$ cat /etc/logrotate.d/tweetedlinks-backend 
/var/www/TweetedLinks/current/log/*.log {
    compress
    copytruncate
    daily
    dateext
    delaycompress
    missingok
    rotate 90
}
This tells it to rotate any logs with the .log extension in /var/www/TweetedLinks/current/log/. You don’t need to worry about permissions or restarting anything, just plonk that in a file and relax. Job done. In case you were wondering, here are what all the options mean:
  • compress - Compress rotated logs. zgrep and zcat are your friends.
  • copytruncate - Copy the log out of the way, and then truncate the existing logs. Some processes don’t handle log files being rotated, and will write logs to an empty file descriptor rather than the new log. This solves that.
  • daily - Rotate logs daily.
  • dateext - Add the date the logs were rotated as the extension rather than a number.
  • delaycompress - Skip compressing the log until the following day. Apparently some processes don’t handle logs being rotated properly and will write to the wrong file descriptor - n.b. does this even have any effect with copytruncate?
  • missingok - Don’t raise an error when there is a missing log file.
  • rotate 90 - Keep up to 90 days worth of logs. There doesn’t appear to be an option to not delete old logs, but you can just set this to a large number, like 36500 to keep 100 years of logs.
Discuss on Hacker News

Testers Required

| Comments

Over the past few weeks I have been working on an app which lets you send and receive SMS messages on your phone using your PC. I first started working on it over a ago but like most projects something more interesting came along (Tweeted Links I think :-p). After seeing a few other apps trying to solve this problem, and although having half-assed implemenatations getting quite a bit of traction, motivation set in and I decided to get back on this.

The original interface I had was Javascript based and ran in the browser. I quite liked this implementation as after you have downloaded an app to your phone, you don’t want to then have to download an app to your PC - and let’s not forget all the issues that come along with developing and maintaining a desktop app… The original version just used JQuery and some horrendous Javascript. I have now moved to using BackboneJS and CoffeeScript which I love working with. I’m using a custom version of Middleman and a watchfile (based on work by @pusewicz) to build everything automagically which works a treat. I’ll put up a post about this later on as it really simplifies development. The interface has gone under a major Lion-esque overhaul as well - if you follow me on Twitter you will have probably seen the screenshots.

Anyway, on to the purpose of this post… I am just finishing up and over the weekend want to get it out to some real people to test. This is the first alpha release so I am expecting testers to give me feedback on their experiences. Requirements other than this are simple… you just need a phone running Android 2.1+. Interested? Leave a comment and I’ll be in contact!

Dear Google, What’s Going On?

| Comments

I don’t know how long this has been going on for, but I first noticed it about a month ago. Certain tube stations in London have non-English names on Google Maps. I haven’t actually visited them, so they could have been renamed as far as I know… I would have thought I would have read about it in The Metro at least.
White City. Victoria. Southwark.

My Problems

| Comments

  • I have to use different applications on different platforms to communicate with people. There is no fully integrated cross platform messaging system. I may SMS one person, and then later talk to them on GTalk, or maybe send them an email if there is something a bit longer than can fit in an SMS. For each of these I need to use a different application (SMS, Adium / IMO, GMail), and more often than not a different application on each platform. Isn’t this what XMPP was supposed to solve?
  • Producing admin interfaces for web applications is a pain. More often than not it is it’s own project in itself. Rails Admin looks promising (for Rails applications), but it still seems a bit bizarre for something that usually has the same basic features for each project, it needs to be reinvented over and over again. Understandably there is some customisation, e.g. branding, but most of the time the basic features repeated over and over are just an ACL and CRUD.

Feeling Relieved

| Comments

So the other day, after maybe a couple too many beers, I left my bag on the bus. Said bag contained my phone and laptop among other non-important things. Luckily it was all insured, but it’ll probably be a good few weeks before I have replacements from the insurance company. I am slightly bummed about it, but really nothing (other than the physical devices) has really been lost. Everything I do either happens in the cloud e.g. email, or is pushed to the cloud e.g. coding. The next day when I was in work I got a few peoples numbers from Gmail who I needed to contact, then sent them an SMS over Skype to let them know I would get back to them later. I then got my temporary phone setup and updated my number on Facebook, so anyone who syncs with that would instantly have my new number. I could have just as easily done this from an internet café in some foreign country. My backup plan for my laptop is the same, non-existant (Time Machine bugs me every couple of weeks that I haven’t backed up for a couple of hundred days). The thing is though, I don’t need to backup. I do everything is in the cloud. (Admittedly though a few things were lost, for example game progress and a couple of rubbish photos - the good ones were posted to Twitter before hand - but everything that mattered to me was available instantly.)