Heroku: see params and sql activity in logs?

前端 未结 6 2162
不思量自难忘°
不思量自难忘° 2020-12-07 22:52

When i view my heroku logs on the server (with heroku logs --tail --app myapp) i see something like this:

2011-06-21T14:09:25+00:00 app[web.1]:          


        
相关标签:
6条回答
  • 2020-12-07 23:36

    Rails doesn't generate those logs when in production mode. http://groups.google.com/group/heroku/browse_thread/thread/d778fafedc9a378a

    0 讨论(0)
  • 2020-12-07 23:37

    The detailed log you want is generated by the function start_processing in log_subscriber.rb.

    action_controller/log_subscriber.rb:

    def start_processing(event)
      payload = event.payload
      params  = payload[:params].except(*INTERNAL_PARAMS)
    
      info "  Processing by #{payload[:controller]}##{payload[:action]} as #{payload[:formats].first.to_s.upcase}"
      info "  Parameters: #{params.inspect}" unless params.empty?
    end
    

    I checked with rails 3.0.4 in development and production environment. In both environments, we have the detailed logs.

    This is an info level log. That's why the debug log level is not changing the output.

    I installed the plugin used by heroku rails_log_stdout (Heroku logging) but I still have the desired output.

    Right now, I can't test with heroku to find out why you don't have all the logs.

    In the heroku example (see Heroku logging, section log retrieval), we don't see the "Processing" and "Parameters" lines. I think that either this method is not called when the app is running on heroku (it is somehow disabled) or heroku skips logs starting with whitespaces. Could you try to log messages starting with whitespaces and see if heroku is showing them?

    0 讨论(0)
  • 2020-12-07 23:38

    You're essentially wanting to show the SQL / params output in the Heroku logs. You can do this by adding the line shown below to the config block within your production.rb file:

    MyAppNameHere::Application.configure do
    
      # add this line
      config.logger = Logger.new(STDOUT)
    
    end
    

    By the way, setting the log level to debug just means that Rails.logger.debug will output to the logs when you're on Heroku

    0 讨论(0)
  • 2020-12-07 23:39

    Looks like the puma server doesn't play well with Heroku. In my project, I tried everything, but it still wouldn't log. I then replaced Puma with Unicorn, and bam, full logs are being shown.

    0 讨论(0)
  • 2020-12-07 23:47

    In your production.rb add config.log_level = :debug and redeploy. That will give you the same logs as development mode :)

    0 讨论(0)
  • 2020-12-07 23:48

    The real problem is actually due to the way Heroku works in conjunction with rails. The right way to solve this is to add: gem 'rails_12factor', group: :production

    See https://devcenter.heroku.com/articles/rails-integration-gems for more info on the matter

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