Logging the caller

It’s so useful to automagically log caller line number and so on. Most languages make it possible via hack involving throwing an exception to yield a stack trace. Some languages explicitly provide this info. In Ruby, it’s possible with the caller array.

Here’s how I used it just now:

  1. def logg
  2.   caller_info = caller[0].gsub! /^.+\/(.*)\.rb:(.*):in `(.*)'/, '\\2:\\3:\\2'
  3.   Rails.logger.debug "[#{caller_info}] - #{id}. Thread#{Thread.current.object_id.to_s(36)}"
  4. end

This will output caller_info in the format: [series_feed:fetch:123]. Which is the file:method:line_number. It’s derived, via the initial regex, from the slightly less log-friendly caller string, path/to/series_feed.rb:123:infetch’.

Announcing Player FM: Podcasts in Your Browser

I’ve launched Player FM today, a product I’ve been wanting to make since podcasting began in 2005! It’s a way to discover, share, and play podcasts in the browser. Works pretty well in mobile browsers as well as the desktop.

Learned a ton in building this thing! A few technologies in here: * Rails 3.1 on the server * Twitter Bootstrap and Font Awesome icons * HAML, SASS+Bourbon, CoffeeScript * HTML5 history to keep playing while the user browses * SoundManager 2 using Flash and falling back to HTML5 audio as appropriate * RSS, JSON, OPML, and plain-text imports and exports

Any ideas for this, let me know. Hope it’s useful!