Class: Steep::TaggedLogging

Inherits:
Logger
  • Object
show all
Defined in:
lib/steep/tagged_logging.rb

Overview

A basic implementation of ActiveSupport::TaggedLogging. Might be able to be replaced by plain logger in the future. github.com/ruby/logger/pull/132

Instance Method Summary collapse

Constructor Details

#initializeTaggedLogging

Returns a new instance of TaggedLogging.



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/steep/tagged_logging.rb', line 6

def initialize(...)
  super
  self.formatter = proc do |severity, datetime, progname, msg|
    # @type var severity: String
    # @type var datetime: Time
    # @type var progname: untyped
    # @type var msg: untyped
    # @type block: String
    "#{datetime.strftime('%Y-%m-%d %H:%M:%S.%L')}: #{severity}: #{formatted_tags} #{msg}\n"
  end
  @thread_key = "steep_tagged_logging_tags:#{object_id}"
  current_tags << "Steep #{VERSION}"
end

Instance Method Details

#current_tagsObject



27
28
29
# File 'lib/steep/tagged_logging.rb', line 27

def current_tags
  Thread.current[@thread_key] ||= []
end

#formatted_tagsObject



35
36
37
# File 'lib/steep/tagged_logging.rb', line 35

def formatted_tags
  current_tags.map { |tag| "[#{tag}]" }.join(" ")
end

#push_tags(*tags) ⇒ Object



31
32
33
# File 'lib/steep/tagged_logging.rb', line 31

def push_tags(*tags)
  current_tags.concat(tags)
end

#tagged(tag) ⇒ Object



20
21
22
23
24
25
# File 'lib/steep/tagged_logging.rb', line 20

def tagged(tag)
  current_tags << tag
  yield
ensure
  current_tags.pop
end