Skip to content
Install · free

Rails

Send logs and errors from Rails to LogNorth: a Railtie, request middleware, the Rails error subscriber, and Active Job.

Terminal window
bundle add lognorth

Add credentials:

config/credentials.yml.enc
lognorth:
url: https://logs.yoursite.com
api_key: your-api-key

That’s it. The gem auto-configures via Railtie. It sends from every environment except development and test.

Prefer environment variables? Set them in config/application.rb instead of credentials:

config.lognorth.url = ENV["LOGNORTH_URL"]
config.lognorth.api_key = ENV["LOGNORTH_API_KEY"]
LogNorth.log("User signed up", { user_id: 123 })
LogNorth.error("Checkout failed", exception, { order_id: 42 })

The middleware automatically:

  • Generates a trace_id per request (or uses X-Trace-ID from the incoming header)
  • Sets X-Trace-ID on the response
  • Logs the request with duration_ms and trace_id as top-level fields
  • All LogNorth.log() and LogNorth.error() calls within the request automatically inherit the same trace_id
class UsersController < ApplicationController
def create
# This log automatically gets the same trace_id as the middleware request log
LogNorth.log("User signed up", { user_id: @user.id })
end
end
# config/application.rb, with the defaults
config.lognorth.enabled = nil # nil: on everywhere except development and test
config.lognorth.middleware = true # Log HTTP requests
config.lognorth.error_subscriber = true # Report exceptions (Rails 7+)
config.lognorth.active_job = true # One event per job, with the trace of the request that enqueued it

The gem reads Current.user when your app defines it, as the Rails authentication generator does. Otherwise, name the user yourself. Use an ID, never an email:

class ApplicationController < ActionController::Base
before_action { LogNorth.user = current_user&.id }
end

The issue page then shows how many users an issue hit. Errors also carry the release, from KAMAL_VERSION, LOGNORTH_RELEASE, GIT_SHA, or your host’s commit variable. At boot the gem logs Release <version> started, and LogNorth draws each deploy as a dashed line on its charts.

Skip health checks and other noisy endpoints:

config/application.rb
config.lognorth.ignored_paths = %w[/healthz /_health /up]

These paths won’t be logged by the middleware. The default is ["/up"]; setting the list replaces it.

Method Behavior
log() Batched (10 events or 5s)
error() Sent immediately with stack trace
Middleware Logs requests with trace_id + duration_ms
Shutdown Auto-flush on exit
ErrorSubscriber Reports exceptions via Rails.error (7+)

error() automatically captures the exception class, file, line, caller method, and backtrace. LogNorth groups errors into issues by them.