Rails: send logs to stderr by default, not stdout.

Send all logs to stderr by default instead of stdout. Fixes a problem
where parsing the output of sandboxed commands could fail, because they
could contain Rails log messages in their stdout.

When we run a command in a sandbox, we call fork+exec to run the command
in the background so we can capture its output. If Rails prints
anything to stdout between the fork and exec calls, then it will be
inadvertently captured along with the command's output. This will break
parsing of the command's output. This can happen if warning messages are
printed by Rails while setting up the sandbox between the fork and exec
calls.

Writing to stderr is also more correct, since stdout is buffered by
default, which means logs could potentially be lost if the process dies
unexpectedly before the buffers are flushed. Stderr is unbuffered by
default, which means logs will always be output immediately.
This commit is contained in:
evazion
2021-11-10 22:45:52 -06:00
parent bb6ce66bfe
commit 3f9a85a828
4 changed files with 4 additions and 4 deletions

View File

@@ -64,7 +64,7 @@ Rails.application.configure do
# Uncomment if you wish to allow Action Cable access from any origin.
# config.action_cable.disable_request_forgery_protection = true
logger = ActiveSupport::Logger.new(STDOUT)
logger = ActiveSupport::Logger.new(STDERR)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)

View File

@@ -76,7 +76,7 @@ Rails.application.configure do
# require "syslog/logger"
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
logger = ActiveSupport::Logger.new(STDOUT)
logger = ActiveSupport::Logger.new(STDERR)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)

View File

@@ -8,7 +8,7 @@ class DelayedJobTimeoutPlugin < ::Delayed::Plugin
end
end
Delayed::Worker.logger = Logger.new(STDOUT, level: :debug)
Delayed::Worker.logger = Logger.new(STDERR, level: :debug)
Delayed::Worker.default_queue_name = "default"
Delayed::Worker.destroy_failed_jobs = false
Delayed::Worker.plugins << DelayedJobTimeoutPlugin