Class: SemanticLogger::Base
- Inherits:
-
Object
- Object
- SemanticLogger::Base
- Defined in:
- lib/semantic_logger/base.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Log
Instance Attribute Summary collapse
-
#level ⇒ Object
Returns the value of attribute level.
-
#name ⇒ Object
Class name to be logged.
Class Method Summary collapse
-
.default_level ⇒ Object
DEPRECATED See SemanticLogger.default_level.
-
.default_level=(level) ⇒ Object
DEPRECATED See SemanticLogger.default_level=.
Instance Method Summary collapse
-
#payload ⇒ Object
Returns [Hash] payload to be added to every log entry in the current scope on this thread.
-
#pop_tags(quantity = 1) ⇒ Object
Remove specified number of tags from the current tag list.
-
#push_tags(*tags) ⇒ Object
Add tags to the current scope.
-
#tagged(*tags) ⇒ Object
(also: #with_tags)
Add the supplied tags to the list of tags to log for this thread whilst the supplied block is active Returns nil if no tags are currently set To support: ActiveSupport::TaggedLogging V3 and above.
-
#tags ⇒ Object
Returns a copy of the [Array] of [String] tags currently active for this thread Returns nil if no tags are set.
-
#with_payload(payload) ⇒ Object
Thread specific context information to be logged with every log entry.
Instance Attribute Details
#level ⇒ Object
Returns the value of attribute level.
14 15 16 |
# File 'lib/semantic_logger/base.rb', line 14 def level @level end |
#name ⇒ Object
Class name to be logged
12 13 14 |
# File 'lib/semantic_logger/base.rb', line 12 def name @name end |
Class Method Details
.default_level ⇒ Object
DEPRECATED See SemanticLogger.default_level
174 175 176 177 |
# File 'lib/semantic_logger/base.rb', line 174 def self.default_level warn "[DEPRECATION] `SemanticLogger::Logger.default_level` is deprecated. Please use `SemanticLogger.default_level` instead." SemanticLogger.default_level end |
.default_level=(level) ⇒ Object
DEPRECATED See SemanticLogger.default_level=
168 169 170 171 |
# File 'lib/semantic_logger/base.rb', line 168 def self.default_level=(level) warn "[DEPRECATION] `SemanticLogger::Logger.default_level=` is deprecated. Please use `SemanticLogger.default_level=` instead." SemanticLogger.default_level = level end |
Instance Method Details
#payload ⇒ Object
Returns [Hash] payload to be added to every log entry in the current scope on this thread. Returns nil if no payload is currently set
157 158 159 |
# File 'lib/semantic_logger/base.rb', line 157 def payload Thread.current[:semantic_logger_payload] end |
#pop_tags(quantity = 1) ⇒ Object
Remove specified number of tags from the current tag list
127 128 129 130 |
# File 'lib/semantic_logger/base.rb', line 127 def (quantity=1) t = Thread.current[:semantic_logger_tags] t.pop(quantity) unless t.nil? end |
#push_tags(*tags) ⇒ Object
Add tags to the current scope
119 120 121 122 123 124 |
# File 'lib/semantic_logger/base.rb', line 119 def * # Need to flatten and reject empties to support calls from Rails 4 = .flatten.collect(&:to_s).reject(&:empty?) t = Thread.current[:semantic_logger_tags] Thread.current[:semantic_logger_tags] = t.nil? ? : t.concat() end |
#tagged(*tags) ⇒ Object Also known as:
Add the supplied tags to the list of tags to log for this thread whilst the supplied block is active Returns nil if no tags are currently set
To support: ActiveSupport::TaggedLogging V3 and above
100 101 102 103 104 105 |
# File 'lib/semantic_logger/base.rb', line 100 def tagged(*) (*) yield ensure (.size) end |
#tags ⇒ Object
Returns a copy of the [Array] of [String] tags currently active for this thread Returns nil if no tags are set
112 113 114 115 116 |
# File 'lib/semantic_logger/base.rb', line 112 def # Since tags are stored on a per thread basis this list is thread-safe t = Thread.current[:semantic_logger_tags] t.nil? ? [] : t.clone end |
#with_payload(payload) ⇒ Object
Thread specific context information to be logged with every log entry
Add a payload to all log calls on This Thread within the supplied block
logger.with_payload(:tracking_number=>12345) do
logger.debug('Hello World')
end
If a log call already includes a pyload, this payload will be merged with the supplied payload, with the supplied payload taking precedence
logger.with_payload(:tracking_number=>12345) do
logger.debug('Hello World', :result => 'blah')
end
146 147 148 149 150 151 152 |
# File 'lib/semantic_logger/base.rb', line 146 def with_payload(payload) current_payload = self.payload Thread.current[:semantic_logger_payload] = current_payload ? current_payload.merge(payload) : payload yield ensure Thread.current[:semantic_logger_payload] = current_payload end |