@@ -17,7 +17,7 @@ After reading this guide, you will know:
View Helpers for Debugging
--------------------------
One common task is to inspect the contents of a variable. In Rails, you can do this with three methods:
One common task is to inspect the contents of a variable. Rails provides three different ways to do this:
*`debug`
*`to_yaml`
...
...
@@ -54,7 +54,7 @@ Title: Rails debugging guide
### `to_yaml`
Displaying an instance variable, or any other object or method, in YAML format can be achieved this way:
Alternatively, calling `to_yaml` on any object converts it to YAML. You can pass this converted object into the `simple format` helper method to format the output. This is how `debug` does its magic.
```html+erb
<%= simple_format @article.to_yaml %>
...
...
@@ -64,9 +64,7 @@ Displaying an instance variable, or any other object or method, in YAML format c
</p>
```
The `to_yaml` method converts the method to YAML format leaving it more readable, and then the `simple_format` helper is used to render each line as in the console. This is how `debug` method does its magic.
As a result of this, you will have something like this in your view:
The above code will render something like this:
```yaml
---!ruby/objectArticle
...
...
@@ -94,7 +92,7 @@ Another useful method for displaying object values is `inspect`, especially when
</p>
```
Will be rendered as follows:
Will render:
```
[1, 2, 3, 4, 5]
...
...
@@ -109,9 +107,9 @@ It can also be useful to save information to log files at runtime. Rails maintai
### What is the Logger?
Rails makes use of the `ActiveSupport::Logger` class to write log information. You can also substitute another logger such as `Log4r` if you wish.
Rails makes use of the `ActiveSupport::Logger` class to write log information. Other loggers, such as `Log4r`, may also be substituted.
You can specify an alternative logger in your `environment.rb` or any environment file:
You can specify an alternative logger in `environment.rb` or any other environment file, for example:
```ruby
Rails.logger=Logger.new(STDOUT)
...
...
@@ -130,7 +128,7 @@ TIP: By default, each log is created under `Rails.root/log/` and the log file is
### Log Levels
When something is logged, it's printed into the corresponding log if the log
level of the message is equal or higher than the configured log level. If you
level of the message is equal to or higher than the configured log level. If you
want to know the current log level, you can call the `Rails.logger.level`
method.
...
...
@@ -143,7 +141,7 @@ config.log_level = :warn # In any environment initializer, or
Rails.logger.level=0# at any time
```
This is useful when you want to log under development or staging, but you don't want to flood your production log with unnecessary information.
This is useful when you want to log under development or staging without flooding your production log with unnecessary information.
TIP: The default Rails log level is `debug` in all environments.
...
...
@@ -207,7 +205,7 @@ Adding extra logging like this makes it easy to search for unexpected or unusual
When running multi-user, multi-account applications, it's often useful
to be able to filter the logs using some custom rules. `TaggedLogging`
in Active Support helps in doing exactly that by stamping log lines with subdomains, request ids, and anything else to aid debugging such applications.
in Active Support helps you do exactly that by stamping log lines with subdomains, request ids, and anything else to aid debugging such applications.