rails - Redirecting console output to a file

前端 未结 7 828
时光取名叫无心
时光取名叫无心 2020-12-12 09:51

On a bash console, if I do this:

cd mydir
ls -l > mydir.txt

The > operator captures the standard input and redirects it to a file; so I

相关标签:
7条回答
  • 2020-12-12 10:45

    If you write the following code in your environment file, it should work.

    if "irb" == $0
      config.logger = Logger.new(Rails.root.join('path_to_log_file.txt'))
    end
    

    You can also rotate the log file using

    config.logger = Logger.new(Rails.root.join('path_to_log_file.txt'), number_of_files, file_roation_size_threshold)
    

    For logging only active record related operations, you can do

    ActiveRecord::Base.logger = Logger.new(Rails.root.join('path_to_log_file.txt'))
    

    This also lets you have different logger config/file for different environments.

    0 讨论(0)
提交回复
热议问题