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 To support: ActiveSupport::TaggedLogging V4 and above.
-
#push_tags(*tags) ⇒ Object
Add tags to the current scope To support: ActiveSupport::TaggedLogging V4 and above.
-
#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 [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
224 225 226 227 |
# File 'lib/semantic_logger/base.rb', line 224 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=
218 219 220 221 |
# File 'lib/semantic_logger/base.rb', line 218 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
205 206 207 |
# File 'lib/semantic_logger/base.rb', line 205 def payload Thread.current[:semantic_logger_payload] end |
#pop_tags(quantity = 1) ⇒ Object
Remove specified number of tags from the current tag list
To support: ActiveSupport::TaggedLogging V4 and above
176 177 178 |
# File 'lib/semantic_logger/base.rb', line 176 def (quantity=1) .pop(quantity) end |
#push_tags(*tags) ⇒ Object
Add tags to the current scope
To support: ActiveSupport::TaggedLogging V4 and above
169 170 171 172 |
# File 'lib/semantic_logger/base.rb', line 169 def * # Check for nil tags Thread.current[:semantic_logger_tags] = self..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
151 152 153 154 155 156 |
# File 'lib/semantic_logger/base.rb', line 151 def tagged(*) (*) yield ensure (.size) end |
#tags ⇒ Object
Returns [Array] of [String] tags currently active for this thread Returns nil if no tags are set
163 164 165 |
# File 'lib/semantic_logger/base.rb', line 163 def Thread.current[:semantic_logger_tags] ||= [] 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
194 195 196 197 198 199 200 |
# File 'lib/semantic_logger/base.rb', line 194 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 |