Taming Ruby on Rails Logging with Lograge and Mezmo
LogDNA is now Mezmo but the product you know and live is here to stay
Ruby on Rails is a powerful and intuitive way to build web applications. With its low barrier of entry, it’s also straightforward to get started. However, the designing of Ruby on Rails (previously referred to as Rails) took place when systems existed on a single server. Every action taken by the web app, from loading a page to sending a form, gets automatically logged in a fragmented manner where multiple logs get generated for each event.
Even for a single instance of a Rails application, a specific event can quickly turn into many unique, unconnected loglines.
One must then keep these in our head to make sense of what happened. For a small app, this is certainly manageable. But as systems scale both horizontally and vertically, things quickly get out of hand. Today's modern deployment paradigms utilizing containers and serverless functions only exacerbate the problem. Troubleshooting and pinpointing issues become a considerable challenge as the structure and verbosity of standard Rails logs increase with scale.
In direct response to this problem, Mathias Meyer developed Lograge "to bring sanity to Rails' noisy and unusable, unparsable and, in the context of running multiple processes and servers, unreadable default logging output."
Remember the multi-line log from above? With Lograge, we get:
Now that the logs are both condensed and parsable, they're actionable.
A key feature of Lograge is the ability to enrich log data with custom information. By modifying the environment configuration as shown, we can add request time, request parameters, ids, exceptions, and anything else your team may find helpful.
To get the additional custom variables in the event payload you must add them to your controller. For instance, we could do something like
Since Meyer designed Lograge to integrate naturally with Ruby's built-in logging, we can use Mezmo's own Ruby/Rails logger to ingest logs from your application. In two short steps, you can have your entire application sending logs to Mezmo.
Step One: Include the logdna gem
Step Two: Configure the Rails logger to use Mezmo with JSON-formatted Lograge
And with that, your logs are both concise and aggregated, allowing you to monitor and troubleshoot your Rails app faster.
LogDNA always takes the top-level "message" key as the human-readable version of a log. It will be used for display in our log viewer, enabling you to quickly scan and "read" your logs while retaining all additional metrics you may send for searching, alerting, and visualization. Rest assured that you can search, alter, and view all data via our context menu.