module Traceable
Constants
- VERSION
Public Class Methods
# File lib/traceable/config.rb, line 31 def self.config @config ||= Config.new end
# File lib/traceable/config.rb, line 25 def self.configure(&_) yield config update_args_config config end
# File lib/traceable/class_methods.rb, line 4 def self.included(base) base.extend(ClassMethods) end
# File lib/traceable/config.rb, line 35 def self.update_args_config Args.set_config_limits( max_string_length: config.max_string_length, max_array_values: config.max_array_values, max_hash_keys: config.max_hash_keys ) end
Public Instance Methods
Create the tracer instance used for generating log messages. If a parent is givent, tags and other settings will be inherited from it. If a parent is not given, it will automatically inherit from the next highest tracer in the call stack, if any.
The default set of tags includes a unique ID string, so all log messages generated from that tracer will have the same ID string. In combination with auto-inheriting from a parent tracer, this means that all tracing messages starting from some common root will have the same ID string to be able to group together related messages in the log.
# File lib/traceable.rb, line 51 def init_tracer(parent: nil, tags: nil) parent ||= Tracer.default_parent @tracer = Tracer.new(parent, tags: tags) end
# File lib/traceable.rb, line 36 def local_tracer @tracer ||= init_tracer end
Generate a log message When called without a block, generates a single log message:
trace "this is a single message" trace.error "something bad happened"
When called with a block, the given message is used to compose a log output at the entry and exit of the block.
trace "doing something nifty" do do_something end
# File lib/traceable.rb, line 24 def trace(msg = nil, **tags) tracer = local_tracer if block_given? tracer.do_block(msg, **tags) { |trace_tags| yield trace_tags } elsif msg tracer.info msg, **tags else tracer end end