Rails logs & stack traces
This course covers two kinds of records a Rails app leaves behind: the development log and Ruby stack traces. It starts with where log/development.log lives and how this app's production environment logs to standard output instead. It then breaks down the Started, Processing by, Parameters and Completed lines, and follows a request halted by a before_action filter. The second half reads a NoMethodError backtrace, picks out the app's own frame among gem frames, and sets a reading order: exception class and message first, then the first frame outside /gems/.
What you'll learn
- ✓Where Rails writes logs in development and production
- ✓What the Started, Processing by, Parameters and Completed lines each report
- ✓How to read a request halted by a before_action filter and redirected
- ✓How a Ruby backtrace is ordered and what each frame line contains
- ✓How to find the app's own frame among gem frames using the /gems/ path segment
- ✓Why to read the exception class and message before any backtrace line
Where Rails logs live
A request fails somewhere, with no browser dev tools open and nobody watching. Rails wrote down what happened anyway, in a plain text file. From this project:
Read the full lesson free →Curriculum
7 lessonsWhere Rails logs live
Development writes every request, query and exception to log/development.log, while this app's production logs to standard output.
Anatomy of a log line
Breaks down the Started, Processing by, Parameters and Completed lines, including status, timing and query counts.
Following one request, start to finish
Follows a request stopped by the require_login filter, redirected to sign-in, and completed as a 302 with zero queries.
What a stack trace actually is
Explains a backtrace as an ordered list of active method calls and compares reading it top down and bottom up.
Finding your code in the trace
Finds the one app frame in a trace of about fifteen lines by scanning for the first path outside a /gems/ directory.
The first line to actually read
Reads the exception class and message first, using a NoMethodError and a RoutingError that has no backtrace.
Putting it together: reading a real failure
Reviews each lesson and applies the full reading order to the NoMethodError to learn what broke and where.