Class: DebugLogging::Configuration
- Inherits:
-
Object
- Object
- DebugLogging::Configuration
- Defined in:
- lib/debug_logging/configuration.rb
Constant Summary collapse
- DEFAULT_ELLIPSIS =
" ✂️ …".freeze
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.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/debug_logging/configuration.rb', line 62 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.
17 18 19 |
# File 'lib/debug_logging/configuration.rb', line 17 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.
12 13 14 |
# File 'lib/debug_logging/configuration.rb', line 12 def args_max_length @args_max_length end |
#class_benchmarks ⇒ Object Also known as: debug_class_benchmarks
Returns the value of attribute class_benchmarks.
14 15 16 |
# File 'lib/debug_logging/configuration.rb', line 14 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.
16 17 18 |
# File 'lib/debug_logging/configuration.rb', line 16 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.
15 16 17 |
# File 'lib/debug_logging/configuration.rb', line 15 def colorized_chain_for_method @colorized_chain_for_method end |
#ellipsis ⇒ Object Also known as: debug_ellipsis
Returns the value of attribute ellipsis.
18 19 20 |
# File 'lib/debug_logging/configuration.rb', line 18 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 }
6 7 8 |
# File 'lib/debug_logging/configuration.rb', line 6 def enabled @enabled end |
#instance_benchmarks ⇒ Object Also known as: debug_instance_benchmarks
Returns the value of attribute instance_benchmarks.
13 14 15 |
# File 'lib/debug_logging/configuration.rb', line 13 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.
11 12 13 |
# File 'lib/debug_logging/configuration.rb', line 11 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.
10 11 12 |
# File 'lib/debug_logging/configuration.rb', line 10 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.
8 9 10 |
# File 'lib/debug_logging/configuration.rb', line 8 def log_level @log_level end |
#logger ⇒ Object Also known as: debug_logger
Returns the value of attribute logger.
7 8 9 |
# File 'lib/debug_logging/configuration.rb', line 7 def logger @logger end |
#mark_scope_exit ⇒ Object Also known as: debug_mark_scope_exit
Returns the value of attribute mark_scope_exit.
19 20 21 |
# File 'lib/debug_logging/configuration.rb', line 19 def mark_scope_exit @mark_scope_exit end |
#methods_to_log ⇒ Object (readonly)
Returns the value of attribute methods_to_log.
20 21 22 |
# File 'lib/debug_logging/configuration.rb', line 20 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
55 56 57 58 59 60 |
# File 'lib/debug_logging/configuration.rb', line 55 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
92 93 94 95 |
# File 'lib/debug_logging/configuration.rb', line 92 def benchmarkable_for?(benchmarks) return @benchmarkable if defined?(@benchmarkable) @benchmarkable = loggable? && self.send(benchmarks) end |
#exit_scope_markable? ⇒ Boolean
96 97 98 99 |
# File 'lib/debug_logging/configuration.rb', line 96 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
79 80 81 82 83 84 85 86 87 |
# File 'lib/debug_logging/configuration.rb', line 79 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
88 89 90 91 |
# File 'lib/debug_logging/configuration.rb', line 88 def loggable? return @loggable if defined?(@loggable) @loggable = logger.send("#{log_level}?") end |
#register(method_lo_log) ⇒ Object
125 126 127 |
# File 'lib/debug_logging/configuration.rb', line 125 def register(method_lo_log) @methods_to_log << method_lo_log end |
#to_hash ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/debug_logging/configuration.rb', line 108 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 |