Rails
Add logging to Rails apps
# Gemfilegem "lognorth", github: "karloscodes/lognorth-sdk-rails"Quick Start
Section titled “Quick Start”Add credentials:
lognorth: url: https://logs.yoursite.com api_key: your-api-keyThat’s it. The gem auto-configures via Railtie.
Manual Configuration
Section titled “Manual Configuration”LogNorth.config( ENV["LOGNORTH_URL"], ENV["LOGNORTH_API_KEY"])LogNorth.log("User signed up", { user_id: 123 })LogNorth.error("Checkout failed", exception, { order_id: 42 })Middleware
Section titled “Middleware”The middleware automatically:
- Generates a
trace_idper request (or usesX-Trace-IDfrom the incoming header) - Sets
X-Trace-IDon the response - Logs the request with
duration_msandtrace_idas top-level fields - All
LogNorth.log()andLogNorth.error()calls within the request automatically inherit the sametrace_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 }) endendOptions
Section titled “Options”config.lognorth.enabled = Rails.env.production?config.lognorth.middleware = true # Log HTTP requestsconfig.lognorth.error_subscriber = true # Report exceptions (Rails 7+)Ignoring Routes
Section titled “Ignoring Routes”Skip health checks and other noisy endpoints:
config.lognorth.ignored_paths = %w[/healthz /_health /up]These paths won’t be logged by the middleware.
How It Works
Section titled “How It Works”| 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. These are used for three-tier issue grouping.