Class: TaggedLogging::Formatter
- Defined in:
- lib/tagged_logging/formatter.rb
Constant Summary collapse
- FORMAT =
"[%s] - %-5s - %s - %s\n"
Instance Method Summary collapse
- #call(severity, time, progname, msg) ⇒ Object
- #clear_tags! ⇒ Object
- #current_tags ⇒ Object
- #pop_tags(size = 1) ⇒ Object
- #push_tags(*tags) ⇒ Object
- #tagged(*tags) ⇒ Object
- #tags_text ⇒ Object
Instance Method Details
#call(severity, time, progname, msg) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/tagged_logging/formatter.rb', line 9 def call(severity, time, progname, msg) str = case msg when ::String msg when ::Exception "#{ msg. } (#{ msg.class })\n | " << (msg.backtrace || []).join("\n | ") else msg.inspect end FORMAT % [format_datetime(time), severity, , msg] end |
#clear_tags! ⇒ Object
39 40 41 |
# File 'lib/tagged_logging/formatter.rb', line 39 def .clear end |
#current_tags ⇒ Object
43 44 45 |
# File 'lib/tagged_logging/formatter.rb', line 43 def Thread.current[:__tagged_logging_current_tags] ||= [] end |
#pop_tags(size = 1) ⇒ Object
35 36 37 |
# File 'lib/tagged_logging/formatter.rb', line 35 def (size = 1) .pop size end |
#push_tags(*tags) ⇒ Object
29 30 31 32 33 |
# File 'lib/tagged_logging/formatter.rb', line 29 def (*) .flatten.reject(&:blank?).tap do || .concat end end |
#tagged(*tags) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/tagged_logging/formatter.rb', line 22 def tagged(*) = (*) yield self ensure (.size) end |
#tags_text ⇒ Object
47 48 49 50 51 52 |
# File 'lib/tagged_logging/formatter.rb', line 47 def = if .any? .collect { |tag| "[#{tag}] " }.join.strip end end |