Class: DebugLogging::Configuration
- Inherits:
-
Object
- Object
- DebugLogging::Configuration
- Defined in:
- lib/debug_logging/configuration.rb
Constant Summary collapse
- DEFAULT_ELLIPSIS =
' ✂️ …'
Instance Attribute Summary collapse
-
#add_invocation_id ⇒ Object
(also: #debug_add_invocation_id)
Returns the value of attribute add_invocation_id.
-
#args_max_length ⇒ Object
(also: #debug_args_max_length)
Returns the value of attribute args_max_length.
-
#class_benchmarks ⇒ Object
(also: #debug_class_benchmarks)
Returns the value of attribute class_benchmarks.
-
#colorized_chain_for_class ⇒ Object
(also: #debug_colorized_chain_for_class)
Returns the value of attribute colorized_chain_for_class.
-
#colorized_chain_for_method ⇒ Object
(also: #debug_colorized_chain_for_method)
Returns the value of attribute colorized_chain_for_method.
-
#ellipsis ⇒ Object
(also: #debug_ellipsis)
Returns the value of attribute ellipsis.
-
#enabled ⇒ Object
(also: #debug_enabled)
For reference, log levels as integers mapped to symbols: LEVELS = { 0 => :debug, 1 => :info, 2 => :warn, 3 => :error, 4 => :fatal, 5 => :unknown }.
-
#instance_benchmarks ⇒ Object
(also: #debug_instance_benchmarks)
Returns the value of attribute instance_benchmarks.
-
#last_hash_max_length ⇒ Object
(also: #debug_last_hash_max_length)
Returns the value of attribute last_hash_max_length.
-
#last_hash_to_s_proc ⇒ Object
(also: #debug_last_hash_to_s_proc)
Returns the value of attribute last_hash_to_s_proc.
-
#log_level ⇒ Object
(also: #debug_log_level)
Returns the value of attribute log_level.
-
#logger ⇒ Object
(also: #debug_logger)
Returns the value of attribute logger.
-
#mark_scope_exit ⇒ Object
(also: #debug_mark_scope_exit)
Returns the value of attribute mark_scope_exit.
-
#methods_to_log ⇒ Object
readonly
Returns the value of attribute methods_to_log.
-
#multiple_last_hashes ⇒ Object
(also: #debug_multiple_last_hashes)
Returns the value of attribute multiple_last_hashes.
Class Method Summary collapse
Instance Method Summary collapse
- #benchmarkable_for?(benchmarks) ⇒ Boolean
- #exit_scope_markable? ⇒ Boolean
-
#initialize(**options) ⇒ Configuration
constructor
A new instance of Configuration.
- #log(message = nil, &block) ⇒ Object
- #loggable? ⇒ Boolean
- #register(method_lo_log) ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(**options) ⇒ Configuration
Returns a new instance of Configuration.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/debug_logging/configuration.rb', line 54 def initialize(**) @enabled = .key?(:enabled) ? [:enabled] : true @logger = .key?(:logger) ? [:logger] : Logger.new($stdout) @log_level = .key?(:log_level) ? [:log_level] : :debug @multiple_last_hashes = .key?(:multiple_last_hashes) ? [:multiple_last_hashes] : false @last_hash_to_s_proc = .key?(:last_hash_to_s_proc) ? [:last_hash_to_s_proc] : nil @last_hash_max_length = .key?(:last_hash_max_length) ? [:last_hash_max_length] : 1_000 @args_max_length = .key?(:args_max_length) ? [:args_max_length] : 1_000 @instance_benchmarks = .key?(:instance_benchmarks) ? [:instance_benchmarks] : false @class_benchmarks = .key?(:class_benchmarks) ? [:class_benchmarks] : false @colorized_chain_for_method = .key?(:colorized_chain_for_method) ? [:colorized_chain_for_method] : false @colorized_chain_for_class = .key?(:colorized_chain_for_class) ? [:colorized_chain_for_class] : false @add_invocation_id = .key?(:add_invocation_id) ? [:add_invocation_id] : true @ellipsis = .key?(:ellipsis) ? [:ellipsis] : DEFAULT_ELLIPSIS @mark_scope_exit = .key?(:mark_scope_exit) ? [:mark_scope_exit] : false @methods_to_log = [] end |
Instance Attribute Details
#add_invocation_id ⇒ Object Also known as: debug_add_invocation_id
Returns the value of attribute add_invocation_id.
9 10 11 |
# File 'lib/debug_logging/configuration.rb', line 9 def add_invocation_id @add_invocation_id end |
#args_max_length ⇒ Object Also known as: debug_args_max_length
Returns the value of attribute args_max_length.
9 10 11 |
# File 'lib/debug_logging/configuration.rb', line 9 def args_max_length @args_max_length end |
#class_benchmarks ⇒ Object Also known as: debug_class_benchmarks
Returns the value of attribute class_benchmarks.
12 13 14 |
# File 'lib/debug_logging/configuration.rb', line 12 def class_benchmarks @class_benchmarks end |
#colorized_chain_for_class ⇒ Object Also known as: debug_colorized_chain_for_class
Returns the value of attribute colorized_chain_for_class.
9 10 11 |
# File 'lib/debug_logging/configuration.rb', line 9 def colorized_chain_for_class @colorized_chain_for_class end |
#colorized_chain_for_method ⇒ Object Also known as: debug_colorized_chain_for_method
Returns the value of attribute colorized_chain_for_method.
9 10 11 |
# File 'lib/debug_logging/configuration.rb', line 9 def colorized_chain_for_method @colorized_chain_for_method end |
#ellipsis ⇒ Object Also known as: debug_ellipsis
Returns the value of attribute ellipsis.
9 10 11 |
# File 'lib/debug_logging/configuration.rb', line 9 def ellipsis @ellipsis end |
#enabled ⇒ Object Also known as: debug_enabled
For reference, log levels as integers mapped to symbols: LEVELS = { 0 => :debug, 1 => :info, 2 => :warn, 3 => :error, 4 => :fatal, 5 => :unknown }
8 9 10 |
# File 'lib/debug_logging/configuration.rb', line 8 def enabled @enabled end |
#instance_benchmarks ⇒ Object Also known as: debug_instance_benchmarks
Returns the value of attribute instance_benchmarks.
12 13 14 |
# File 'lib/debug_logging/configuration.rb', line 12 def instance_benchmarks @instance_benchmarks end |
#last_hash_max_length ⇒ Object Also known as: debug_last_hash_max_length
Returns the value of attribute last_hash_max_length.
9 10 11 |
# File 'lib/debug_logging/configuration.rb', line 9 def last_hash_max_length @last_hash_max_length end |
#last_hash_to_s_proc ⇒ Object Also known as: debug_last_hash_to_s_proc
Returns the value of attribute last_hash_to_s_proc.
9 10 11 |
# File 'lib/debug_logging/configuration.rb', line 9 def last_hash_to_s_proc @last_hash_to_s_proc end |
#log_level ⇒ Object Also known as: debug_log_level
Returns the value of attribute log_level.
9 10 11 |
# File 'lib/debug_logging/configuration.rb', line 9 def log_level @log_level end |
#logger ⇒ Object Also known as: debug_logger
Returns the value of attribute logger.
9 10 11 |
# File 'lib/debug_logging/configuration.rb', line 9 def logger @logger end |
#mark_scope_exit ⇒ Object Also known as: debug_mark_scope_exit
Returns the value of attribute mark_scope_exit.
9 10 11 |
# File 'lib/debug_logging/configuration.rb', line 9 def mark_scope_exit @mark_scope_exit end |
#methods_to_log ⇒ Object (readonly)
Returns the value of attribute methods_to_log.
12 13 14 |
# File 'lib/debug_logging/configuration.rb', line 12 def methods_to_log @methods_to_log end |
#multiple_last_hashes ⇒ Object Also known as: debug_multiple_last_hashes
Returns the value of attribute multiple_last_hashes.
9 10 11 |
# File 'lib/debug_logging/configuration.rb', line 9 def multiple_last_hashes @multiple_last_hashes end |
Class Method Details
.config_pointer(type, method_to_log) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/debug_logging/configuration.rb', line 47 def config_pointer(type, method_to_log) # Methods names that do not match the following regex can't be part of an ivar name # /[a-zA-Z_][a-zA-Z0-9_]*/ # Thus we have to use a different form of the method name that is compatible with ivar name conventions "@debug_logging_config_#{type}_#{Digest::MD5.hexdigest(method_to_log.to_s)}".to_sym end |
Instance Method Details
#benchmarkable_for?(benchmarks) ⇒ Boolean
89 90 91 92 93 |
# File 'lib/debug_logging/configuration.rb', line 89 def benchmarkable_for?(benchmarks) return @benchmarkable if defined?(@benchmarkable) @benchmarkable = loggable? && send(benchmarks) end |
#exit_scope_markable? ⇒ Boolean
95 96 97 98 99 |
# File 'lib/debug_logging/configuration.rb', line 95 def exit_scope_markable? return @exit_scope_markable if defined?(@exit_scope_markable) @exit_scope_markable = loggable? && mark_scope_exit end |
#log(message = nil, &block) ⇒ Object
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/debug_logging/configuration.rb', line 72 def log( = nil, &block) return unless enabled return unless logger if block_given? logger.send(log_level, &block) else logger.send(log_level, ) end end |
#loggable? ⇒ Boolean
83 84 85 86 87 |
# File 'lib/debug_logging/configuration.rb', line 83 def loggable? return @loggable if defined?(@loggable) @loggable = logger.send("#{log_level}?") end |
#register(method_lo_log) ⇒ Object
129 130 131 |
# File 'lib/debug_logging/configuration.rb', line 129 def register(method_lo_log) @methods_to_log << method_lo_log end |
#to_hash ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/debug_logging/configuration.rb', line 111 def to_hash { logger: logger, log_level: log_level, multiple_last_hashes: multiple_last_hashes, last_hash_to_s_proc: last_hash_to_s_proc, last_hash_max_length: last_hash_max_length, args_max_length: args_max_length, instance_benchmarks: instance_benchmarks, class_benchmarks: class_benchmarks, colorized_chain_for_method: colorized_chain_for_method, colorized_chain_for_class: colorized_chain_for_class, add_invocation_id: add_invocation_id, ellipsis: ellipsis, mark_scope_exit: mark_scope_exit } end |