Log ruby on rails application running in phusion passenger to aws cloudwatch

24 views Asked by At

I'm struggling to configure logger of my Ruby on Rails application, which runs in a Phusion Passenger Docker image on AWS ECS, to log to AWS CloudWatch.

I've configured the application to log everything to STDOUT. However, for some reason, CloudWatch is still not picking up application logs, only server logs for now.

# application.rb
config.log_level = ENV.fetch('LOG_LEVEL', 'info')
config.log_tags = [:request_id]
config.log_formatter = ::Logger::Formatter.new

logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)

I SSHed into one of the EC2 instances, then accessed the Docker container where the Ruby on Rails app is running. There, I found that logs are dumped into /var/log/nginx/access.log and /var/log/nginx/error.log.

Currently, what CloudWatch is picking:


2024-03-26T17:58:58.596+01:00    *** Running /etc/my_init.d/00_regen_ssh_host_keys.sh...
2024-03-26T17:58:58.605+01:00    *** Running /etc/my_init.d/10_syslog-ng.init...
2024-03-26T17:58:58.656+01:00    Mar 26 16:58:58 eb8de6fe99e3 syslog-ng[13]: syslog-ng starting up; version='3.25.1'
2024-03-26T17:58:59.632+01:00    *** Running /etc/my_init.d/30_presetup_nginx.sh...
2024-03-26T17:58:59.641+01:00    *** Running /etc/my_init.d/40_db_actions.sh...
2024-03-26T17:58:59.650+01:00    *** Running /etc/my_init.d/50_delayed_job.sh...
2024-03-26T17:58:59.654+01:00    *** Start Delayed jobs ***
2024-03-26T17:59:00.163+01:00    fatal: not a git repository (or any of the parent directories): .git
2024-03-26T17:59:08.248+01:00    delayed_job: process with pid 27 started.
2024-03-26T17:59:08.369+01:00    *** Booting runit daemon...
2024-03-26T17:59:08.369+01:00    *** Runit started as PID 29
2024-03-26T17:59:08.422+01:00    Mar 26 16:59:08 eb8de6fe99e3 cron[36]: (CRON) INFO (pidfile fd = 3)
2024-03-26T17:59:08.422+01:00    Mar 26 16:59:08 eb8de6fe99e3 cron[36]: (CRON) INFO (Running @reboot jobs)
2024-03-26T17:59:09.652+01:00    ok: run: /etc/service/nginx-log-forwarder: (pid 43) 0s
2024-03-26T18:17:01.444+01:00    Mar 26 17:17:01 eb8de6fe99e3 CRON[942]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
2024-03-26T19:17:01.465+01:00    Mar 26 18:17:01 eb8de6fe99e3 CRON[2394]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)

I thought that because of 2024-03-26T17:59:09.652+01:00 ok: run: /etc/service/nginx-log-forwarder: (pid 43) 0s, logs from the Docker container should be forwarded to the EC2 server where the AWSLogs agent should pick them up and send them to CloudWatch.

Another solution could be to dump everything to production.log or staging.log and then configure the AWSLogs agent to watch those files. However, I'm unsure how to configure the agent to watch files that are inside the Docker container.

0

There are 0 answers