Module: LogBuddy
- Extended by:
- Utils
- Defined in:
- lib/log_buddy.rb,
lib/log_buddy/mixin.rb,
lib/log_buddy/utils.rb,
lib/log_buddy/version.rb
Overview
LogBuddy is a developer tool for easy logging while testing, debugging, and inspecting.
The d
log method to give you easy, concise output of variables with their names and values.
Requiring ‘log_buddy’ will automatically mixin the d
method into Object. You can avoid this behavior by setting SAFE_LOG_BUDDY to true in your environment before requiring LogBuddy.
Examples:
a = "foo"
@a = "my var"
def
"woof!"
end
d { a } # logs "a = 'foo'"
d { @a } # logs "@a = 'my var'"
d { } # logs "bark = woof!"
Defined Under Namespace
Modules: Mixin, Utils, Version
Class Method Summary collapse
-
.init(options = {}) ⇒ Object
Configure and include LogBuddy into Object.
- .log_to_stdout? ⇒ Boolean
- .logger ⇒ Object
-
.mixin_to_object ⇒ Object
Add the LogBuddy::Mixin to Object instance and class level.
- .use_awesome_print? ⇒ Boolean
Methods included from Utils
arg_and_blk_debug, debug, obj_to_string, parse_args, read_line, stdout_puts
Class Method Details
.init(options = {}) ⇒ Object
Configure and include LogBuddy into Object. You can pass in any of the following configuration options:
-
:logger
- the logger instance that LogBuddy should use (if not provided, tries to default to RAILS_DEFAULT_LOGGER, and then to a STDOUT logger). -
:log_to_stdout
- whether LogBuddy should also log to STDOUT, very helpful for Autotest (default istrue
). -
:disabled
- when true, LogBuddy will not produce any output -
:use_awesome_print
- when true, LogBuddy will log object with awesome_print
34 35 36 37 38 39 40 |
# File 'lib/log_buddy.rb', line 34 def self.init( = {}) @logger = [:logger] @log_to_stdout = .has_key?(:log_to_stdout) ? [:log_to_stdout] : true @use_awesome_print = .has_key?(:use_awesome_print) ? [:use_awesome_print] : false @disabled = ([:disabled] == true) mixin_to_object end |
.log_to_stdout? ⇒ Boolean
57 58 59 |
# File 'lib/log_buddy.rb', line 57 def log_to_stdout? @log_to_stdout end |
.logger ⇒ Object
52 53 54 55 |
# File 'lib/log_buddy.rb', line 52 def logger return @logger if @logger @logger = init_default_logger end |
.mixin_to_object ⇒ Object
Add the LogBuddy::Mixin to Object instance and class level.
43 44 45 46 47 48 |
# File 'lib/log_buddy.rb', line 43 def self.mixin_to_object Object.class_eval { include LogBuddy::Mixin extend LogBuddy::Mixin } end |
.use_awesome_print? ⇒ Boolean
61 62 63 |
# File 'lib/log_buddy.rb', line 61 def use_awesome_print? @use_awesome_print end |