Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add ability to disable LogBuddy without having to remove your debug s…

…tatements [#2]
  • Loading branch information...
commit 8251aa48e5ac1f37e2027d49f22368f62222ff6f 1 parent 1bb2065
@jasonrudolph jasonrudolph authored
View
6 README.rdoc
@@ -8,7 +8,7 @@ log_buddy is your friendly little log buddy at your side, helping you dev, debug
Require the init.rb file to use log_buddy. By default, it will add two methods to every object at the instance and class level: "d" and "logger". To use log_buddy without the automatic object intrusion, set ENV["SAFE_LOG_BUDDY"] = true before requiring the init.rb.
-You can use your own logger with Logbuddy by passing it into init's options hash:
+You can use your own logger with LogBuddy by passing it into init's options hash:
LogBuddy.init :default_logger => Logger.new('my_log.log')
@@ -38,6 +38,10 @@ in the block and the result. Examples:
See examples.rb for live examples you can run.
+When you occasionally want to disable LogBuddy (but you don't want to have to remove all your debug statements), you can pass the :disabled option into init's options hash:
+
+ LogBuddy.init :disabled => true
+
== REQUIREMENTS:
* Ruby 1.8.6 or JRuby (tested with 1.1RC3)
View
7 examples/log_buddy_init_example.rb
@@ -25,6 +25,13 @@ def reset_safe_log_buddy_mode
ENV["SAFE_LOG_BUDDY"] = nil
end
+ it "should be disabled when the :disabled key is true" do
+ LogBuddy.init(:disabled => true)
+ fake_logger = mock('logger')
+ LogBuddy.stubs(:logger).returns(fake_logger)
+ fake_logger.expects(:debug).never
+ d { "Hello, World!" }
+ end
end
end
View
2  lib/log_buddy.rb
@@ -26,9 +26,11 @@ module LogBuddy
# * <tt>:logger</tt> - the logger instance that LogBuddy should use (if not provided,
# tries to default to RAILS_DEFAULT_LOGGER, and then to a STDOUT logger).
# * <tt):log_to_stdout</tt> - whether LogBuddy should _also_ log to STDOUT, very helpful for Autotest (default is +true+).
+ # * <tt>:disabled</tt> - when true, LogBuddy will not produce any output
def self.init(options = {})
@logger = options[:logger]
@log_to_stdout = options.has_key?(:log_to_stdout) ? options[:log_to_stdout] : true
+ @disabled = (options[:disabled] == true)
mixin_to_object
end
View
1  lib/log_buddy/utils.rb
@@ -2,6 +2,7 @@ module LogBuddy
module Utils
def debug(obj)
+ return if @disabled
str = obj_to_string(obj)
stdout_puts(str) if log_to_stdout?
logger.debug(str)
Please sign in to comment.
Something went wrong with that request. Please try again.