0

My ruby application is running on platform Ruby 2.7 on Amazon Linux2. The application create a logger by using below code:

Rails.logger = Logger.new(File.join(Rails.root, 'log', 'server.log'))

The application runs well, but the server.log file doesn't exist in var/log

I tried replace above code with below:

Rails.logger = Logger.new('server.log')

Still cannot find server.log file. Can you please tell which directory the server.log will be in?

lei lei
  • 1,753
  • 4
  • 19
  • 44
  • Where is `Rails.root`? In other words, which folder on this machine stores the rails project? `File.join(Rails.root, 'log', 'server.log')` means exactly what it looks like: `/path/to/rails/application/log/server.log`. – Tom Lord Aug 12 '21 at 15:13
  • I'm guessing the rails application does **not** live directly in `/var`. That would be very weird. – Tom Lord Aug 12 '21 at 15:14
  • @TomLord Thanks Tom. If I want to put the logging file under /var/log/server.log, how should I modify the code? – lei lei Aug 12 '21 at 23:39
  • `Rails.logger = Logger.new('/var/log/server.log')`??! – Tom Lord Aug 13 '21 at 10:39
  • This would be an unusual choice, however; the `/var/log` folder is generally reserved for **system logs**, not application logs. – Tom Lord Aug 13 '21 at 10:42

0 Answers0