class Syslogger::SimpleFormatter

Borrowed from ActiveSupport. See: github.com/rails/rails/blob/master/activesupport/lib/active_support/tagged_logging.rb

Public Instance Methods

call(_severity, _timestamp, _progname, msg) click to toggle source

This method is invoked when a log event occurs.

# File lib/syslogger.rb, line 171
def call(_severity, _timestamp, _progname, msg)
  "#{tags_text}#{msg}"
end
clear_tags!() click to toggle source
# File lib/syslogger.rb, line 192
def clear_tags!
  current_tags.clear
end
current_tags() click to toggle source

Fix: github.com/crohr/syslogger/issues/29 See: github.com/rails/rails/blob/master/activesupport/lib/active_support/tagged_logging.rb#L47

# File lib/syslogger.rb, line 198
def current_tags
  # We use our object ID here to avoid conflicting with other instances
  thread_key = @thread_key ||= "syslogger_tagged_logging_tags:#{object_id}".freeze
  Thread.current[thread_key] ||= []
end
pop_tags(size = 1) click to toggle source
# File lib/syslogger.rb, line 188
def pop_tags(size = 1)
  current_tags.pop size
end
push_tags(*tags) click to toggle source
# File lib/syslogger.rb, line 182
def push_tags(*tags)
  tags.flatten.reject { |i| i.respond_to?(:empty?) ? i.empty? : !i }.tap do |new_tags|
    current_tags.concat(new_tags).uniq!
  end
end
tagged(*tags) { |self| ... } click to toggle source
# File lib/syslogger.rb, line 175
def tagged(*tags)
  new_tags = push_tags(*tags)
  yield self
ensure
  pop_tags(new_tags.size)
end
tags_text() click to toggle source
# File lib/syslogger.rb, line 204
def tags_text
  tags = current_tags
  tags.collect { |tag| "[#{tag}] " }.join if tags.any?
end