a month ago
At some point, my rails HTTP logs stopped showing on projects logs. I have tried many different approaches and even used your agent without success
Pinned Solution
a month ago
Yes, you correct. I was able to fix the problem with a very similar solution that we used before with lograge, but once we migrated to rails_semantic_logger, I (and the agent) believed this wasn't necessary since I was setting semantic logger to use stdout.
config.logger = ActiveSupport::Logger.new($stdout)
.tap { |logger| logger.formatter = ::Logger::Formatter.new }
.then { |logger| ActiveSupport::TaggedLogging.new(logger) }
NOTE: I had Ruby Stdout Buffering and Log Level correctly set.
Thank you
2 Replies
a month ago
This thread has been opened as a public bounty so the community can help solve it. The thread and any further activity are now visible to everyone.
Status changed to Open Railway • 27 days ago
a month ago
Hi andremendonca,
Based on your description of Rails HTTP logs missing from your Railway project logs, here is a comprehensive checklist to ensure your logs are being correctly emitted to stdout without buffering issues
- Railway Environment Variable
Ensure you have the following environment variable set in your Railway project settings:
RAILS_LOG_TO_STDOUT=true
- Production Configuration
In config/environments/production.rb, verify that your logger configuration is not inadvertently suppressing output. By default, many Rails templates use the RAILS_LOG_TO_STDOUT variable to toggle the logger. Ensure your setup looks similar to this to guarantee stdout delivery with proper tagging:
if ENV["RAILS_LOG_TO_STDOUT"].present?
logger = ActiveSupport::Logger.new($stdout)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end
Also, ensure that config.public_file_server.enabled is set correctly if you are expecting logs related to static asset serving, though this is secondary to the primary application logs
- Ruby Stdout Buffering
One common reason for logs not appearing in realtime (or at all in certain failure modes) is Ruby's internal stdout buffering. You can force an immediate flush by setting STDOUT.sync to true. The best place to do this is in config/boot.rb:
$stdout.sync = true
Alternatively, if you are using the standard Rails 10-factor gem or the built-in Rails 5+ configuration, setting the RAILS_LOG_TO_STDOUT environment variable usually handles this sync behavior automatically. However, explicitly setting it in boot.rb is a failsafe way to ensure every write is immediately emitted to the Railway log stream
- Log Level Check
Finally, double check that your config.log_level is not set too high (e.g., :fatal or :error) in production, which would filter out standard :info level HTTP request logs:
config.log_level = :info
This combination should ensure your Rails HTTP logs are captured and displayed correctly within the Railway dashboard
bmatsko
Hi andremendonca, Based on your description of Rails HTTP logs missing from your Railway project logs, here is a comprehensive checklist to ensure your logs are being correctly emitted to stdout without buffering issues 1. Railway Environment Variable Ensure you have the following environment variable set in your Railway project settings: RAILS_LOG_TO_STDOUT=true 2. Production Configuration In config/environments/production.rb, verify that your logger configuration is not inadvertently suppressing output. By default, many Rails templates use the RAILS_LOG_TO_STDOUT variable to toggle the logger. Ensure your setup looks similar to this to guarantee stdout delivery with proper tagging: if ENV["RAILS_LOG_TO_STDOUT"].present? logger = ActiveSupport::Logger.new($stdout) logger.formatter = config.log_formatter config.logger = ActiveSupport::TaggedLogging.new(logger) end Also, ensure that config.public_file_server.enabled is set correctly if you are expecting logs related to static asset serving, though this is secondary to the primary application logs 3. Ruby Stdout Buffering One common reason for logs not appearing in realtime (or at all in certain failure modes) is Ruby's internal stdout buffering. You can force an immediate flush by setting STDOUT.sync to true. The best place to do this is in config/boot.rb: $stdout.sync = true Alternatively, if you are using the standard Rails 10-factor gem or the built-in Rails 5+ configuration, setting the RAILS_LOG_TO_STDOUT environment variable usually handles this sync behavior automatically. However, explicitly setting it in boot.rb is a failsafe way to ensure every write is immediately emitted to the Railway log stream 4. Log Level Check Finally, double check that your config.log_level is not set too high (e.g., :fatal or :error) in production, which would filter out standard :info level HTTP request logs: config.log_level = :info This combination should ensure your Rails HTTP logs are captured and displayed correctly within the Railway dashboard
a month ago
Yes, you correct. I was able to fix the problem with a very similar solution that we used before with lograge, but once we migrated to rails_semantic_logger, I (and the agent) believed this wasn't necessary since I was setting semantic logger to use stdout.
config.logger = ActiveSupport::Logger.new($stdout)
.tap { |logger| logger.formatter = ::Logger::Formatter.new }
.then { |logger| ActiveSupport::TaggedLogging.new(logger) }
NOTE: I had Ruby Stdout Buffering and Log Level correctly set.
Thank you
Status changed to Solved passos • 17 days ago