There’s a special kind of hell reserved for debugging production issues with bad logs. You know the one. A customer reports an error. You check the logs. You see:
[2024-10-26 03:42:18] ERROR: Something went wrong
Thanks, Rails. Super helpful. Which user? Which request? What actually went wrong? Who knows! Not you, that’s for sure.
I spent six months in that hell. Then I spent two weeks fixing our logging, and I haven’t been back since.
The Problem With Default Rails Logging
Rails logging out of the box is… fine. For development. You get nice colorized output, you see SQL queries, it’s lovely:
# What you see in development Started GET "/users/123" for 127.0.0.1 at 2024-10-26 10:30:00 +0000 Processing by UsersController#show as HTML Parameters: {"id"=>"123"} User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 123], ["LIMIT", 1]] Rendered users/show.html.erb within layouts/application (Duration: 2.4ms | Allocations: 1234) Completed 200 OK in 45ms (Views: 32.1ms | ActiveRecord: 8.9ms | Allocations…