aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGaurish Sharma <contact@gaurishsharma.com>2012-09-03 19:33:59 +0530
committerGaurish Sharma <contact@gaurishsharma.com>2012-09-03 19:33:59 +0530
commitcd59277110b3a4db81691111c6aa4734f9cad998 (patch)
treea91a1e752c6205b2db9e81d0a8fc31db29d0bdfb
parent198d63f984199bcf5a232eb6482b50fc58d3b4f5 (diff)
downloadrails-cd59277110b3a4db81691111c6aa4734f9cad998.tar.gz
rails-cd59277110b3a4db81691111c6aa4734f9cad998.tar.bz2
rails-cd59277110b3a4db81691111c6aa4734f9cad998.zip
Add section about tagged logging
Tagged logging for which Rails has support since [3.2](http://guides.rubyonrails.org/3_2_release_notes.html#tagged-logging). It is trivial & useful but unless somebody explicitly searches API docs, he/she may not know about it.  Hence, I added it in guides. 
-rw-r--r--guides/source/debugging_rails_applications.textile16
1 files changed, 16 insertions, 0 deletions
diff --git a/guides/source/debugging_rails_applications.textile b/guides/source/debugging_rails_applications.textile
index 667f2d2140..99430e1e5f 100644
--- a/guides/source/debugging_rails_applications.textile
+++ b/guides/source/debugging_rails_applications.textile
@@ -189,6 +189,22 @@ Redirected to #<Post:0x20af760>
Completed in 0.01224 (81 reqs/sec) | DB: 0.00044 (3%) | 302 Found [http://localhost/posts]
</shell>
+h4. Tagged Logging
+
+When running a multi-user, multi-account application, it’s a great help to be able to filter the log by who did what. 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.
+<ruby>
+logger.tagged("custom_tag") { logger.info "Date is #{Time.now.to_date}" }
+logger.tagged("custom_tag", "gaurish") { logger.info "multiple tags are supported" }
+</ruby>
+
+Now, you filter logs by searching for +custom_tag+ & logs with tag +custom_tag+ would be returned. Here's an example using <tt>grep</tt> command
+<shell>
+ $ grep custom_tag log/development.log
+[custom_tag] Date is 2012-09-03
+[custom_tag] [gaurish] multiple tags are supported
+</shell>
+Tagged Logging makes it easier to filter logs & exact selected lines only. For more details and examples, check the API documentation, see "<tt>TaggedLogging</tt>":http://api.rubyonrails.org/classes/ActiveSupport/TaggedLogging.html
+
Adding extra logging like this makes it easy to search for unexpected or unusual behavior in your logs. If you add extra logging, be sure to make sensible use of log levels, to avoid filling your production logs with useless trivia.
h3. Debugging with the +debugger+ gem