6.6. Logging

Both this and the previous chapter mentioned that you could see the executed queries, errors, and other details about the requests in a log file. Depending on the environment you are in, Rails will log a certain amount of information in log\development.log, log\test.log, or log\production.log. The log folder will also contain a server.log file for the Web server (for example, Mongrel).

When you look at the development.log file after having visited the front page of the blog, you see an entry similar to the following:

Processing ArticlesController#index (for 127.0.0.1 at 2009-01-28 11:28:11) [GET]
  [4;36;1mArticle Load (0.0ms)[0m   [0;1mSELECT * FROM "articles" WHERE (published
= 't' AND published_at <= '2009-01-28 16:28:11') ORDER BY published_at DESC LIMIT 1
OFFSET 0[0m
[4;35;1mSQL (0.0ms)[0m   [0mSELECT count(*) AS count_all FROM "articles" WHERE
(published = 't' AND published_at <= '2009-01-28 16:28:11') [0m
Rendering template within layouts/articles
Rendering articles/index
  [4;36;1mSQL (0.0ms)[0m   [0;1mSELECT count(*) AS count_all FROM "comments" WHERE
("comments".article_id = 2) [0m
Rendered articles/_article (10.0ms)
Completed in 29ms (View: 18, DB: 0) | 200 OK [http://localhost/]

This tells you a whole lot of information: the type of request received, the IP it came from and the timestamp, which controller and action executed your request, the rendered templates, and the queries that were executed behind the scenes. It also tells you the time that it took to execute ...

Get Ruby on Rails® for Microsoft Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.