Class: Sapience::Base
- Inherits:
-
Object
- Object
- Sapience::Base
- Defined in:
- lib/sapience/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#filter ⇒ Object
Class name to be logged.
-
#name ⇒ Object
Class name to be logged.
Instance Method Summary collapse
-
#fast_tag(tag, &block) ⇒ Object
:nodoc:.
-
#level ⇒ Object
Returns the current log level if set, otherwise it returns the global default log level.
-
#level=(level) ⇒ Object
Set the logging level for this logger.
-
#measure(level, message, params = {}, &block) ⇒ Object
(also: #benchmark)
Dynamically supply the log level with every measurement call.
-
#payload ⇒ Object
Returns [Hash] payload to be added to every log entry in the current scope on this thread.
-
#pop_tags(quantity = 1) ⇒ Object
:nodoc:.
-
#push_tags(*tags) ⇒ Object
:nodoc:.
-
#silence(new_level = :error, &block) ⇒ Object
:nodoc:.
-
#tagged(*tags, &block) ⇒ Object
(also: #with_tags)
:nodoc:.
-
#tags ⇒ Object
:nodoc:.
-
#with_payload(payload) ⇒ Object
Thread specific context information to be logged with every log entry.
Instance Attribute Details
#filter ⇒ Object
Class name to be logged
4 5 6 |
# File 'lib/sapience/base.rb', line 4 def filter @filter end |
#name ⇒ Object
Class name to be logged
4 5 6 |
# File 'lib/sapience/base.rb', line 4 def name @name end |
Instance Method Details
#fast_tag(tag, &block) ⇒ Object
:nodoc:
142 143 144 |
# File 'lib/sapience/base.rb', line 142 def fast_tag(tag, &block) Sapience.fast_tag(tag, &block) end |
#level ⇒ Object
Returns the current log level if set, otherwise it returns the global default log level
21 22 23 |
# File 'lib/sapience/base.rb', line 21 def level @level || Sapience.config.default_level end |
#level=(level) ⇒ Object
Set the logging level for this logger
Note: This level is only for this particular instance. It does not override
the log level in any logging instance or the default log level
Sapience.config.default_level
Must be one of the values in Sapience::LEVELS, or nil if this logger instance should use the global default level
14 15 16 17 |
# File 'lib/sapience/base.rb', line 14 def level=(level) @level_index = Sapience.config.level_to_index(level) @level = Sapience.config.index_to_level(@level_index) end |
#measure(level, message, params = {}, &block) ⇒ Object Also known as: benchmark
Dynamically supply the log level with every measurement call
102 103 104 105 106 107 108 109 |
# File 'lib/sapience/base.rb', line 102 def measure(level, , params = {}, &block) index = Sapience.config.level_to_index(level) if level_index <= index measure_internal(level, index, , params, &block) else block.call(params) if block end end |
#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
171 172 173 |
# File 'lib/sapience/base.rb', line 171 def payload Thread.current[:sapience_payload] end |
#pop_tags(quantity = 1) ⇒ Object
:nodoc:
132 133 134 |
# File 'lib/sapience/base.rb', line 132 def (quantity = 1) Sapience.(quantity) end |
#push_tags(*tags) ⇒ Object
:nodoc:
127 128 129 |
# File 'lib/sapience/base.rb', line 127 def (*) Sapience.(*) end |
#silence(new_level = :error, &block) ⇒ Object
:nodoc:
137 138 139 |
# File 'lib/sapience/base.rb', line 137 def silence(new_level = :error, &block) Sapience.silence(new_level, &block) end |
#tagged(*tags, &block) ⇒ Object Also known as:
:nodoc:
114 115 116 |
# File 'lib/sapience/base.rb', line 114 def tagged(*, &block) Sapience.tagged(*, &block) end |
#tags ⇒ Object
:nodoc:
122 123 124 |
# File 'lib/sapience/base.rb', line 122 def Sapience. 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
160 161 162 163 164 165 166 |
# File 'lib/sapience/base.rb', line 160 def with_payload(payload) current_payload = self.payload Thread.current[:sapience_payload] = current_payload ? current_payload.merge(payload) : payload yield ensure Thread.current[:sapience_payload] = current_payload end |