Rails logging lab

See how every kind of Rails log line lands on Laravel Cloud.

Pick an approach below and fire it. Every action reports back the request_id so you can find the exact lines in the log viewer.

Environment
production
Rails / Ruby
8.1.4 ยท 4.0.7
Log level
INFO
LOG_FORMAT
text
LOGRAGE
off
STRUCTURED_EVENTS
on

The logger

Text lines through Rails.logger, the way most Rails apps log.

01

Rails.logger

Standard logger

Writes at a given severity. Anything below the configured level is dropped (production defaults to info). The block form is only evaluated if the level is enabled.

Rails.logger.info "message"
Rails.logger.debug { expensive_string }
02

Tagged logging

ActiveSupport::TaggedLogging

Prefixes every line inside the block with [tags]. Production already tags every request line with its request_id via config.log_tags.

Rails.logger.tagged("billing", "user:42") do
  Rails.logger.info "message"
end

Structured

Named events with data attached instead of free-form text.

03

Rails.event

Structured event reporter

Rails 8.1

The new first-party structured logging API. Events carry a payload, tags, context and source location, and are printed as JSON lines here. Rails emits its own request and job events through it too.

Rails.event.set_context(request_id: ...)
Rails.event.tagged("checkout") do
  Rails.event.notify("user.signed_up", user_id: 1)
end
04

Instrumentation

Notifications + LogSubscriber

How Rails produces its own log lines: instrument a block, and a LogSubscriber turns the event and its duration into a line.

ActiveSupport::Notifications.instrument("checkout.demo") do
  ...
end

# DemoLogSubscriber < ActiveSupport::LogSubscriber
def checkout(event) = info { "#{event.duration}ms" }

Errors

Reported errors and real crashes, including multi-line backtraces.

05

Rails.error

Error reporter

The standard interface for error trackers like Sentry or Nightwatch. It doesn't log on its own, so this app subscribes a logger to it.

Rails.error.report(error, handled: true, severity: :error)
Rails.error.handle { risky_call }
06

Unhandled exception

500 Internal Server Error

Raises from the controller. Rails logs the error with a multi-line backtrace and renders the 500 page. Use the browser back button to return.

raise RuntimeError, "boom"

Jobs & stdio

Lines written outside the request, or outside the logger altogether.

07

Active Job

Background job (async adapter)

Runs in-process on a background thread. Job lines are tagged [ActiveJob] [LogDemoJob] [job_id] and include enqueue, perform and failure lines.

LogDemoJob.perform_later("message")
08

Raw STDOUT / STDERR

Bypasses the logger

Writes straight to the process streams. Checks whether the platform captures both, and whether it treats stderr as errors.

$stdout.puts "message"
$stderr.puts "message"
warn "message"

Edge cases

Inputs that tend to break log pipelines.

Burst Many lines in one request
Huge line One line of N bytes
Multi-line Embedded newlines
Unicode + ANSI Emoji, CJK, colour codes
Every level debug through unknown