3.
config.logger = ActiveSupport::BufferedLogger.new(File.join(ENV['RAILS_ENV'], "#{Rails.root}/logs/#{ENV['RAILS_ENV']}.log"))
How do I create a folder when the rails application starts so that the folder is created when the application boots up and the logs can access the created folder.
Where should I add the code in which folder under \config so that it loads the code which creates a directory first and then uses the config? Thank you.
Copy Paste it config/environments/development.rb
log_file_name = "#{Rails.root}/logs/#{ENV['RAILS_ENV']}.log"
unless File.exist?(File.dirname(log_file_name))
FileUtils.mkdir_p(File.dirname(log_file_name))
File.new(log_file_name, 'a+')
end
config.logger = ActiveSupport::BufferedLogger.new(File.join("#{Rails.root}", "logs", "#{ENV['RAILS_ENV']}.log"))
For 'a+' in File.new see this LINK
You can also use the config/application.rb LINK