Zero-config JSON logging for Ruby on Rails

LogStruct is a new way to add type-safe, dev-ops friendly JSON logging to any Ruby on Rails application. Just add the gem to your Gemfile, and your Rails app will print beautiful JSON logs that are easy to search, filter, and visualize.

Installation

Enable JSON structured logging for your application:

1. Add to your Gemfile

gem "logstruct"

2. Bundle install

bundle install

Monitoring and Dashboards

Structured JSON logs are easy to parse, so you can quickly set up metrics, alerts, and dashboards.

Loading...

Loading visualization examples...

Features

Type-safe with Sorbet

LogStruct is fully type-checked with Sorbet. Your logs are guaranteed to have the correct structure and valid data.

Advanced Filtering and Scrubbing

Automatically redact sensitive information like emails, credit cards, passwords, IPs, and SSNs from your log output.

Integrates with Everything

Integrates with ActiveJob, ActionMailer, ActiveStorage, Lograge, Sidekiq, Carrierwave, and more to provide consistent structured logging. (Open a PR to add support for your favorite gem!)

Error Reporting

Smart and configurable error handling behaviors. Automatic error reporting integration with Sentry, Bugsnag, Rollbar, and Honeybadger.

Cloud-Ready

Compatible with AWS CloudWatch, Google Cloud Logging, and other cloud monitoring services that can filter and parse JSON log data. LogStruct provides Terraform types so your IaC config is always type-safe and up-to-date.

Tagged Logging

Add tags to your logs for better querying and aggregation. Perfect for tracking requests, background jobs, or custom workflows.

Project Status

Frequently Asked Questions

Do I need to use Sorbet?

No, you can use LogStruct even if you don't use Sorbet. You can use the regular Rails logger as usual without worrying about Sorbet types. sorbet-runtime is a dependency, but you can even configure LogStruct to completely ignore type-checking errors. (Not recommended!)

Is LogStruct free?

Yes, LogStruct is completely free and open source under the MIT license. Pull requests and contributions are welcome!

Why was LogStruct built?

DocSpring was originally using the lograge gem to format our request logs as JSON. We realized that we had a lot of other plain text logs that would be useful for CloudWatch metrics and dashboards. We wrote much of this code in our own app before deciding to extract it and release it as a gem. (It was also a great opportunity to learn more about Sorbet.)

What about other logging gems?

Several other gems provide structured logging for Rails apps, including Rails Semantic Logger, Lograge, Logstasher, and Logcraft. LogStruct focuses on powerful filtering and scrubbing, structured error handling, and type‑safety across integrations. See the comparison page for a detailed breakdown.