From 606b62af5d4ac8aa3a38266e9053767ed452bc5f Mon Sep 17 00:00:00 2001 From: miloops Date: Tue, 16 Sep 2008 13:39:08 -0300 Subject: Updated Debugging Rails Applications: use title case in all headings, added changelog, some other small changes to the guide. Added myself to authors. --- .../debugging/debugging_rails_applications.txt | 43 ++++++++++++++-------- 1 file changed, 28 insertions(+), 15 deletions(-) (limited to 'railties/doc/guides/debugging') diff --git a/railties/doc/guides/debugging/debugging_rails_applications.txt b/railties/doc/guides/debugging/debugging_rails_applications.txt index eb1135d094..37d4dd19d6 100644 --- a/railties/doc/guides/debugging/debugging_rails_applications.txt +++ b/railties/doc/guides/debugging/debugging_rails_applications.txt @@ -1,4 +1,4 @@ -Debugging Rails applications +Debugging Rails Applications ============================ This guide covers how to debug Ruby on Rails applications. By referring to this guide, you will be able to: @@ -8,7 +8,13 @@ This guide covers how to debug Ruby on Rails applications. By referring to this * Learn the different ways of debugging * Analyze the stack trace -== View helpers for debugging +== View Helpers for Debugging + +One common task is to inspect the contents of a variable. In Rails, you can do this with three methods: + +* `debug` +* `to_yaml` +* `inspect` === debug @@ -40,8 +46,7 @@ attributes_cache: {} Title: Rails debugging guide ---------------------------------------------------------------------------- - -=== do it yourself +=== to_yaml Displaying an instance variable, or any other object or method, in yaml format can be achieved this way: @@ -72,6 +77,8 @@ attributes_cache: {} Title: Rails debugging guide ---------------------------------------------------------------------------- +=== inspect + Another useful method for displaying object values is `inspect`, especially when working with arrays or hashes, it will print the object value as a string, for example: [source, html] @@ -91,13 +98,13 @@ Will be rendered as follows: Title: Rails debugging guide ---------------------------------------------------------------------------- -== The logger +== The Logger === What is it? -Rails makes use of ruby’s standard `logger`, `Log4r`, or another logger that provides a similar interface can also be substituted if you wish. +Rails makes use of ruby's standard `logger` to write log information. You can also substitute another logger such as `Log4R` if you wish. -If you want to change the logger you can specify it in your `environment.rb` or any environment file. +If you want to change the logger you can specify it in your +environment.rb+ or any environment file. [source, ruby] ---------------------------------------------------------------------------- @@ -114,9 +121,9 @@ config.logger = Log4r::Logger.new("Application Log") ---------------------------------------------------------------------------- [TIP] -By default, each log is created under `RAILS_ROOT/log/` and the log file name is `environment_name.log`. +By default, each log is created under `RAILS_ROOT/log/` and the log file name is +environment_name.log+. -=== Log levels +=== Log Levels When something is logged it's printed into the corresponding log if the message log level is equal or higher than the configured log level. If you want to know the current log level just call `ActiveRecord::Base.logger.level` method. @@ -133,7 +140,7 @@ This is useful when you want to log under development or staging, but you don't [TIP] Rails default log level is +info+ in production mode and +debug+ in development and test mode. -=== Sending messages +=== Sending Messages To write in the current log use the `logger.(debug|info|warn|error|fatal)` method from within a controller, model or mailer: @@ -236,7 +243,7 @@ In development mode, you can dynamically `require \'ruby-debug\'` instead of res In order to use Rails debugging you'll need to be running either *WEBrick* or *Mongrel*. For the moment, no alternative servers are supported. -=== The shell +=== The Shell As soon as your application calls the `debugger` method, the debugger will be started in a debugger shell inside the terminal window you've fired up your application server and you will be placed in the ruby-debug's prompt `(rdb:n)`. The _n_ is the thread number. @@ -305,7 +312,7 @@ If we do it again, this time using just `l`, the next ten lines of the file will And so on until the end of the current file, when the end of file is reached, it will start again from the beginning of the file and continue again up to the end, acting as a circular buffer. -=== The context +=== The Context When we start debugging your application, we will be placed in different contexts as you go through the different parts of the stack. A context will be created when a stopping point or an event is reached. It has information about the suspended program which enable a debugger to inspect the frame stack, evaluate variables from the perspective of the debugged program, and contains information about the place the debugged program is stopped. @@ -349,7 +356,7 @@ The debugger can list, stop, resume and switch between running threads, the comm This command is very helpful, among other occasions, when you are debugging concurrent threads and need to verify that there are no race conditions in your code. -=== Inspecting variables +=== Inspecting Variables Any expression can be evaluated in the current context, just type it! @@ -422,7 +429,7 @@ We can use also `display` to start watching variables, this is a good way of tra The variables inside the displaying list will be printed with their values after we move in the stack. To stop displaying a variable use `undisplay _n_` where _n_ is the variable number (1 in the last example). -=== Step by step +=== Step by Step Now you should know where you are in the running trace and be able to print the available variables. But lets continue and move on with the application execution. @@ -601,4 +608,10 @@ set listsize 25 * link:http://railscasts.com/episodes/56-the-logger[Ryan Bate's logger screencast] * link:http://bashdb.sourceforge.net/ruby-debug.html[Debugging with ruby-debug] * link:http://cheat.errtheblog.com/s/rdebug/[ruby-debug cheat sheet] -* link:http://wiki.rubyonrails.org/rails/pages/HowtoConfigureLogging[Ruby on Rails Wiki: How to Configure Logging] \ No newline at end of file +* link:http://wiki.rubyonrails.org/rails/pages/HowtoConfigureLogging[Ruby on Rails Wiki: How to Configure Logging] + +== Changelog == + +http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/5[Lighthouse ticket] + +* September 16, 2008: initial version by link:../authors.html#miloops[Emilio Tagua] \ No newline at end of file -- cgit v1.2.3