Logging each line with abbreviated session id

I like to grep through logs and see all lines that involve a single
session.

I make my own custom log for this purpose, say foo.log.

I have been sticking 32 char session_ids into an instance array of my
Logger, and using @session_ids.index(session_id) as a unique
abbreviation string for logging.
Abbreviation is handy when several people are working on a single
customer problem - you can’t read a 32 char string over the phone and
get it right.

Since there are only a few dozen concurrent sessions, three alphanumeric
characters are enough to uniquely specify all the sessions in a single
day’s logs.

The ‘array index’ approach has lots of problems:

  1. server restarts change the abbreviation.
  2. sessions spanning the midnight logrotate roll-over are scrambled
    because I reset the ids into a fresh array at that time. If I didn’t,
    three chars wouldn’t be enough.
  3. each webserver has a private list of abbreviations, so it takes extra
    work to track a single session across multiple servers.
  4. it’s clumsy to garbage collect old sessions.

In previous C/C++ systems I memory-mapped a logging id to a file, and
wrote code to manage the sharing (locking). In Rails, I guess I can do
the same with the database. But the problem seems so commonplace that I
want to make sure I’m not overlooking an existing solution.

I’m a web newbie, and the value of the Session ID seems so universal to
all web apps, and the shortcomings likewise so universal, that somebody
must have a multi-process (even multi-system) abbreviator already? One
that can “roll-over” all but the open sessions on command?