5

When I'm looking at the views rendered by ror framework, everything gets logged on the console, but when the ajax call is made to my server by some action user performed on the page, I don't get that part logged, I can't see the SQL executed in the console, and it's difficult to debug issues.

What can I do to turn on the logging for ajax requests as well?

Gandalf StormCrow
  • 25,788
  • 70
  • 174
  • 263
  • 1
    they should be getting logged by default - try running tail on log/development.log - does that have a different result than rails server in the console? – house9 Dec 09 '15 at 17:25
  • @house9 no they're the same, nothing more in development log – Gandalf StormCrow Dec 09 '15 at 17:37
  • On the network tab in the browser do you see the ajax HTTP request to your rails server? If yes it must be logging something to the development.log ? – house9 Dec 09 '15 at 17:51
  • @house9 yes it hits my server, and server returns the payload, I can also debug that call by putting a `binding.pry` in the controller method, and it will halt there once the ajax request is made, but nothing still in the logs – Gandalf StormCrow Dec 09 '15 at 17:57
  • it doesn't even log `Started POST "/foo" for 127.0.0.1 at 2015-12-09 ... Processing by FoosController#create as JSON` for the ajax request? if not there might be some before or around filter in your application controller or possibly in a gem you are using that is silencing the logging? – house9 Dec 09 '15 at 18:11
  • @house9 no it doesn't even log that, there is not filters other than security and to set some instance variables, I do include these `include ActionController::Live and include Services::RowGrid`. ActionController live for streaming data to front-end, and RowGrid is a service in the `app/services/` folder that has some business logic – Gandalf StormCrow Dec 09 '15 at 18:17
  • sorry - I am out of ideas :( – house9 Dec 09 '15 at 18:22
  • @house9 thanks, I m out to, been trying to debunk this one for a while. – Gandalf StormCrow Dec 09 '15 at 18:30
  • In chrome network panel there is an option "Save as HAR with data" . Can you perform an ajax request, and share that HAR output ? – lorefnon Dec 15 '15 at 19:02

2 Answers2

2
  1. Try hitting the AJAX endpoint directly from your browser, or better yet with curl.

    In either case check if the response, especially the headers and compare to another end endpoint, which is being logged correctly.

  2. Use something like pry to confirm you're actually hitting the code you think you're hitting.

  3. Check for spring. It's easy to get caught out hitting another process.

Community
  • 1
  • 1
davetapley
  • 17,000
  • 12
  • 60
  • 86
1

I would have added this as a comment, but I dont have enough rep.. in your browser developer tools, go to the network tab, and ensure that the request is even going out to the sever. chances are its not if everything else is getting logged correctly. assuming you are in a development environment, you also may want to ensure your logger level is on debug mode, to show more descriptive information like the SQL. if you need to run a logger in a specific environment file (even though it should be setup by default), try:

config.logger = Logger.new(STDOUT)

Marrs
  • 706
  • 7
  • 10