Logging
You may not have thought of it this way, but youâve been working
with Rails logs since the first time you entered script/server
. All of that information flowing
by is the development log. You can find all of it in the log directory of your application, stored in
the development.log file.
(There are also test.log and
production.log files there for use
when your application runs in test or development mode, as described in
the next chapter.) Heroku has a logs tab in its editing interface, but
it doesnât present nearly as much information.
While Rails is certainly generous with the information that it
sends to the log in development mode, that sheer volume can make it hard
to find things. It may also not be sending what you want to see. If you
want to send something specific to the log, use the logger
object in your model, controller, or view. In a model or
controller, this would look like:
logger.info 'This is a message to send to the log'
while in the view it would look like:
<% logger.info 'This is a message to send to the log' %>
You can use <%=
rather than
<%
to send the message to both the
screen and the logger if you want to combine a visible message with a
permanent record:
<%= logger.info 'This is a message for the view and the log' %>
The user would then see âThis is a
message for the view and the log
â on her screen, and it would
also be stored in the log file.
One piece of information that is logged and is worth pointing out is timing information. Youâll find lines ...
Get Learning Rails 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.