Class: Sapience::Base
- Inherits:
-
Object
- Object
- Sapience::Base
- Includes:
- LogMethods
- Defined in:
- lib/sapience/base.rb
Overview
rubocop:disable ClassLength
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
- #app_name ⇒ Object
-
#default_formatter ⇒ Object
Returns [Sapience::Formatters::Default] formatter default for this subscriber.
-
#fast_tag(tag, &block) ⇒ Object
:nodoc:.
-
#host ⇒ Object
Allow host name to be set globally or per subscriber.
-
#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.
-
#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
(also: #tags=)
: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.
Methods included from LogMethods
#debug, #debug?, #error, #error!, #error?, #fatal, #fatal!, #fatal?, #info, #info?, #level_to_index, #log_with_exception, #log_with_level, #measure, #measure_debug, #measure_error, #measure_fatal, #measure_info, #measure_trace, #measure_warn, #trace, #trace?, #warn, #warn?
Instance Attribute Details
#filter ⇒ Object
Class name to be logged
6 7 8 |
# File 'lib/sapience/base.rb', line 6 def filter @filter end |
#name ⇒ Object
Class name to be logged
6 7 8 |
# File 'lib/sapience/base.rb', line 6 def name @name end |
Instance Method Details
#app_name ⇒ Object
112 113 114 |
# File 'lib/sapience/base.rb', line 112 def app_name Sapience.app_name end |
#default_formatter ⇒ Object
Returns [Sapience::Formatters::Default] formatter default for this subscriber
108 109 110 |
# File 'lib/sapience/base.rb', line 108 def default_formatter Sapience::Formatters::Default.new end |
#fast_tag(tag, &block) ⇒ Object
:nodoc:
103 104 105 |
# File 'lib/sapience/base.rb', line 103 def fast_tag(tag, &block) Sapience.fast_tag(tag, &block) end |
#host ⇒ Object
Allow host name to be set globally or per subscriber
117 118 119 |
# File 'lib/sapience/base.rb', line 117 def host Sapience.config.host end |
#level ⇒ Object
Returns the current log level if set, otherwise it returns the global default log level
24 25 26 |
# File 'lib/sapience/base.rb', line 24 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
17 18 19 20 |
# File 'lib/sapience/base.rb', line 17 def level=(level) @level_index = Sapience.config.level_to_index(level) @level = Sapience.config.index_to_level(@level_index) 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
146 147 148 |
# File 'lib/sapience/base.rb', line 146 def payload Thread.current[:sapience_payload] end |
#pop_tags(quantity = 1) ⇒ Object
:nodoc:
93 94 95 |
# File 'lib/sapience/base.rb', line 93 def (quantity = 1) Sapience.(quantity) end |
#push_tags(*tags) ⇒ Object Also known as:
:nodoc:
87 88 89 |
# File 'lib/sapience/base.rb', line 87 def (*) Sapience.(*) end |
#silence(new_level = :error, &block) ⇒ Object
:nodoc:
98 99 100 |
# File 'lib/sapience/base.rb', line 98 def silence(new_level = :error, &block) Sapience.silence(new_level, &block) end |
#tagged(*tags, &block) ⇒ Object Also known as:
:nodoc:
74 75 76 |
# File 'lib/sapience/base.rb', line 74 def tagged(*, &block) Sapience.tagged(*, &block) 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
135 136 137 138 139 140 141 |
# File 'lib/sapience/base.rb', line 135 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 |