Rails 7 logging lab

See how every kind of Rails 7 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
7.2.4 ยท 3.3.12
Log level
INFO
LOG_FORMAT
text
LOGRAGE
off

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

Hash message

Structured data, pre-Rails 8.1

Rails 7 has no Rails.event, so structured data usually means passing a Hash to the logger. The default formatter prints it with #inspect; with LOG_FORMAT=json it becomes fields on the JSON line.

Rails.logger.info(event: "user.signed_up", user_id: 42)
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