Rails production logs under log/production.log aren't being tailed

Hi there. I have a deployed rails app. Logs are located in log/production.log, which I don’t think I’ve configured anywhere.

I can do fly ssh console and tail -f log/production.log to see my logs, but I don’t see them in my Fly monitoring dashboard or via fly logs. All I see there is about my server spinning up or down and listening.

I’m under the impression that I should see them from this section - is this wrong?

I could use RAILS_LOG_TO_STDOUT, but I’d like to get the log file working. My fly.toml doesn’t have any details around logging or any env vars.

Let me know what other info is needed to help out.

Logging to standard out is how you route your logs to the monitoring dashboard and fly logs. This is configured in config/environments/production.rb. If you like you can tell Rails to log to both stdout and log/production.log. More information can be found in Multiple Logs for Resiliency · The Fly Blog

1 Like

Thanks!

Do you think it’s worth adding RAILS_LOG_TO_STDOUT in the env of the generated fly.toml for rails projects? I might have messed something up when setting up my project, but it’s been a bit annoying to not log to the dashboard by default.

For reference, this is in my (rails 7) generated production.rb

  if ENV["RAILS_LOG_TO_STDOUT"].present?
    logger = ActiveSupport::Logger.new(STDOUT)
    logger.formatter = config.log_formatter
    config.logger = ActiveSupport::TaggedLogging.new(logger)
  end

It is added to the Dockerfile that we generate for Rails < 7.1 applications. Rails 7.1 and later will default to stdout.

Try running bin/rails generate dockerfile. More information can be found here: GitHub - fly-apps/dockerfile-rails: Provides a Rails generator to produce Dockerfiles and related files.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.