10

How can I turn off the verbose active record logging in production? (Like every SQL statement is logged) My logs are filling up really fast because I have background jobs running loads of queries. This is fine on my development server but I don't need this logged in production.

Nick Barrett
  • 1,051
  • 2
  • 11
  • 28
  • Not saying I disagree with you, however, I like to keep the SQL logs around and deal with log file size issues through rotation. Do you have this setup? If not, what OS are you on in prod? – steakchaser Mar 03 '14 at 02:09
  • 2
    My issue is I am using papertrail on heroku and if I do not control the log size I run out of data transfer in minutes. I just don't need this logged for this particular background job. So if there is a way to turn it off 'temporarily' that could work too – Nick Barrett Mar 03 '14 at 02:22

1 Answers1

22

To turn off completely, just add this to your environment file (i.e. production.rb):

config.active_record.logger = nil

See AR guide (section 3.6):

config.active_record.logger accepts a logger conforming to the interface of Log4r or the default Ruby Logger class, which is then passed on to any new database connections made. You can retrieve this logger by calling logger on either an Active Record model class or an Active Record model instance. Set to nil to disable logging.

There's more options (like selectively turning on / off) documented in other posts. See Disable Rails SQL logging in console as a starting point.

Community
  • 1
  • 1
steakchaser
  • 5,198
  • 1
  • 26
  • 34
  • 2
    Thanks. I ended up putting ActiveRecord::Base.logger = nil in the particular job I didnt want to log – Nick Barrett Mar 03 '14 at 03:01
  • 1
    You'll also lose your `logger` object in models if you do this... You'll have to change all `logger.info` calls in your models to `Rails.logger.info` etc. – kino1 Oct 04 '18 at 07:55