Class: Syslogger::SimpleFormatter
- Inherits:
-
Logger::Formatter
- Object
- Logger::Formatter
- Syslogger::SimpleFormatter
- Defined in:
- lib/syslogger.rb
Overview
Borrowed from ActiveSupport. See: github.com/rails/rails/blob/master/activesupport/lib/active_support/tagged_logging.rb
Instance Method Summary collapse
-
#call(_severity, _timestamp, _progname, msg) ⇒ Object
This method is invoked when a log event occurs.
- #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, _timestamp, _progname, msg) ⇒ Object
This method is invoked when a log event occurs.
171 172 173 |
# File 'lib/syslogger.rb', line 171 def call(_severity, , _progname, msg) "#{}#{msg}" end |
#clear_tags! ⇒ Object
192 193 194 |
# File 'lib/syslogger.rb', line 192 def .clear end |
#current_tags ⇒ Object
198 199 200 201 202 |
# File 'lib/syslogger.rb', line 198 def # 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) ⇒ Object
188 189 190 |
# File 'lib/syslogger.rb', line 188 def (size = 1) .pop size end |
#push_tags(*tags) ⇒ Object
182 183 184 185 186 |
# File 'lib/syslogger.rb', line 182 def (*) .flatten.reject { |i| i.respond_to?(:empty?) ? i.empty? : !i }.tap do || .concat().uniq! end end |
#tagged(*tags) ⇒ Object
175 176 177 178 179 180 |
# File 'lib/syslogger.rb', line 175 def tagged(*) = (*) yield self ensure (.size) end |
#tags_text ⇒ Object
204 205 206 207 |
# File 'lib/syslogger.rb', line 204 def = .collect { |tag| "[#{tag}] " }.join if .any? end |