Troubleshooting

Production logs are still text

LogStruct is on only in the processes it recognizes as servers or job workers (Puma, rails server, Unicorn, Thin, Falcon, Sidekiq and good_job start). Rake tasks, rails runner, Solid Queue's bin/jobs and other job runners keep Rails' logger. Set LOGSTRUCT_ENABLED=true in those processes' environment. See When LogStruct Runs.

Nothing changes in development

LogStruct is off in development by default. Start the server with LOGSTRUCT_ENABLED=true bin/rails server, or turn it on in an initializer (example).

Some lines are still text

  • Lines a gem or your code writes with its own Logger.new($stdout), puts or warn don't go through Rails' logger, so LogStruct never sees them. Point those loggers at Rails.logger.
  • Text logged through Rails.logger is a JSON line with the text in msg. That includes the lines of Rails components and gems LogStruct has no integration for. Log a Hash to get fields of your own.
  • Output from before the app loads LogStruct (Bundler, or a boot script) is text.

A value I need is filtered

A key is filtered when one of its words is a sensitive word (session_id, auth_provider and cookie_consent are), when it's in filters.filter_keys, or when Rails' filter_parameters match it. Rails matches its Symbols and Strings anywhere in a key, so a new app's :token filters token_count and its :_key filters cache_key. Rename the key, change filter_parameters, or filter only the keys you list:

config/initializers/logstruct.rb
LogStruct.configure do |config|
  # Filter the keys in filter_keys (and Rails' filter_parameters) only, not every key with a
  # sensitive word in it, such as session_id or cookie_consent
  config.filters.filter_matchers.reject! { |matcher| matcher.label == "default_sensitive_pattern" }
  # So list the other keys you want filtered
  config.filters.filter_keys += [:api_key, :session_token]
end

A String that looks like an email, a card number, a phone number or an SSN is scrubbed wherever it appears. Turn off the scrubbers you don't want in Filtering Sensitive Data.

Errors and 404s at fatal level

An error your app didn't handle is an error line with src rails and the response's status, written where Rails would log its block of text, at Rails' level for these errors: fatal unless you change it. Routing errors (404) and the other errors Rails turns into a response of their own are logged too, as Rails logs them. Rails' settings change both:

# config/environments/production.rb
config.action_dispatch.debug_exception_log_level = :error
# Leave out the errors Rails turns into a 404, 422 and so on
config.action_dispatch.log_rescued_responses = false

Type errors raise in tests after upgrading

Since 0.2.0, error_handling_modes.type_checking_errors is ReportProduction: a Sorbet type error raises in development and test, and is logged and reported in production. The errors were there before; LogStruct only logged them. Fix them, or set the mode to Log while you do (see Error Handling).

My Lograge or Sidekiq settings are ignored

LogStruct sets up Lograge and Sidekiq's logger after config/initializers run, so it replaces what another initializer set. Add request fields with lograge_custom_options, or turn the integration off (enable_lograge, enable_sidekiq) to keep your own setup.

Lines are missing at exit

SemanticLogger writes lines from a background thread, and writes the ones still queued when the process exits. A process killed with SIGKILL (or out of memory) loses its queued lines. In a script that must not lose any, call SemanticLogger.flush after the lines that matter.

Email hashes differ between apps

Hashes are keyed with filters.hash_salt, or a key derived from each app's secret_key_base. Set the same hash_salt (from your credentials) in every app whose lines you compare, and keep it when secret_key_base changes.

Lines with src logstruct

These are errors inside LogStruct (an integration that couldn't build its line, for example), or, with no error tracker set up, errors LogStruct was asked to report. In development and test LogStruct's own errors raise instead (error_handling_modes.logstruct_errors), so that they're found early. Please open an issue for one that isn't a report.

Values end with "more items" or _more_keys

Lines have size limits: 100 keys per Hash, 10 items per Array, 20 lines per backtrace and 32 KB per string. Change them with config.limits.