Module: RailsLogstasher::TaggedLogging::Formatter
- Defined in:
- lib/rails-logstasher/tagged_logging.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#call(severity, timestamp, progname, msg) ⇒ Object
This method is invoked when a log event occurs.
- #clear_tags! ⇒ Object
- #current_request_tags ⇒ Object
- #current_tags ⇒ Object
- #log_type=(log_type) ⇒ Object
- #pop_tags(size = 1) ⇒ Object
- #process_entry ⇒ Object
- #process_tags(tags) ⇒ Object
- #push_request_tags(tags) ⇒ Object
- #push_tags(*tags) ⇒ Object
- #tagged(*tags) ⇒ Object
Instance Method Details
#call(severity, timestamp, progname, msg) ⇒ Object
This method is invoked when a log event occurs.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rails-logstasher/tagged_logging.rb', line 21 def call(severity, , progname, msg) @entry = nil if msg.class == RailsLogstasher::Event @entry = msg else @entry = RailsLogstasher::Event.new(Rails.logger) @entry. = msg end @entry.fields['severity'] = severity @entry.type = @log_type () () process_entry #TODO Should we do anything with progname? What about source? super(severity, , progname, @entry.to_json) end |
#clear_tags! ⇒ Object
80 81 82 83 |
# File 'lib/rails-logstasher/tagged_logging.rb', line 80 def .clear .clear end |
#current_request_tags ⇒ Object
89 90 91 |
# File 'lib/rails-logstasher/tagged_logging.rb', line 89 def Thread.current[:activesupport_tagged_logging_request_tags] ||= [] end |
#current_tags ⇒ Object
85 86 87 |
# File 'lib/rails-logstasher/tagged_logging.rb', line 85 def Thread.current[:activesupport_tagged_logging_tags] ||= [] end |
#log_type=(log_type) ⇒ Object
93 94 95 |
# File 'lib/rails-logstasher/tagged_logging.rb', line 93 def log_type=(log_type) @log_type = log_type end |
#pop_tags(size = 1) ⇒ Object
76 77 78 |
# File 'lib/rails-logstasher/tagged_logging.rb', line 76 def (size = 1) .pop size end |
#process_entry ⇒ Object
40 41 42 43 44 45 |
# File 'lib/rails-logstasher/tagged_logging.rb', line 40 def process_entry entry_processor = RailsLogstasher.config[:entry_processor] return unless entry_processor && entry_processor.class == Proc entry_processor.call @entry end |
#process_tags(tags) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/rails-logstasher/tagged_logging.rb', line 64 def () .each do |tag| if tag.class == Hash tag.each_pair do |k,v| @entry.fields[k] = v end else @entry. << tag end end end |
#push_request_tags(tags) ⇒ Object
60 61 62 |
# File 'lib/rails-logstasher/tagged_logging.rb', line 60 def () Thread.current[:activesupport_tagged_logging_request_tags] = end |
#push_tags(*tags) ⇒ Object
54 55 56 57 58 |
# File 'lib/rails-logstasher/tagged_logging.rb', line 54 def (*) .flatten.reject(&:blank?).tap do || .concat end end |
#tagged(*tags) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/rails-logstasher/tagged_logging.rb', line 47 def tagged(*) = (*) yield self ensure (.size) end |