We have set logger as STDOUT in the rails configuration.
config.log_level = :info
config.logger = Logger.new(STDOUT)
We are expecting these logs in kubectl logs as well as datadog logs but STDOUT is not showing up there. We tried below code to test it.
def method_name
system('echo testing logging') - this shows up in kubectl/datadog logs
Rails.logger.info('STDOUT - testing logging') - this does not show up in kubectl/datadog log
end
CodePudding user response:
We have changed the logger setting to output the logs to container file descriptor.
Reference: https://blog.eq8.eu/til/ruby-logs-and-puts-not-shown-in-docker-container-logs.html
CodePudding user response:
Try to use the default config and make sure to set the environment variable RAILS_LOG_TO_STDOUT=true
, for your deployment/replica set, and in production mode (RAILS_ENV=production
). (In dev mode it always logs to console per default).
Actually, the official rails docker images used to have that set, but the newer recommended ruby docker images - of course - do not have Rails specific environment variables set.
(more: search for RAILS_LOG_TO_STDOUT in the release notes here, and see PR here)