Class: SemanticLogger::Base
- Inherits:
-
Object
- Object
- SemanticLogger::Base
- Defined in:
- lib/semantic_logger/base.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Log
Constant Summary collapse
- @@default_level =
Initial default Level for all new instances of SemanticLogger::Logger
:info
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
Returns the global default log level for new Logger instances.
-
.default_level=(level) ⇒ Object
Allow for setting the global default log level This change only applies to new loggers, existing logger levels will not be changed in any way.
Instance Method Summary collapse
-
#payload ⇒ Object
Returns [Hash] payload to be added to every log entry in the current scope on this thread.
-
#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.
-
#with_tags(*tags) ⇒ Object
(also: #tagged)
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.
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
Returns the global default log level for new Logger instances
218 219 220 |
# File 'lib/semantic_logger/base.rb', line 218 def self.default_level @@default_level end |
.default_level=(level) ⇒ Object
Allow for setting the global default log level This change only applies to new loggers, existing logger levels will not be changed in any way
213 214 215 |
# File 'lib/semantic_logger/base.rb', line 213 def self.default_level=(level) @@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
195 196 197 |
# File 'lib/semantic_logger/base.rb', line 195 def payload Thread.current[:semantic_logger_payload] end |
#tags ⇒ Object
Returns [Array] of [String] tags currently active for this thread Returns nil if no tags are set
166 167 168 |
# File 'lib/semantic_logger/base.rb', line 166 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
184 185 186 187 188 189 190 |
# File 'lib/semantic_logger/base.rb', line 184 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 |
#with_tags(*tags) ⇒ Object Also known as: tagged
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
150 151 152 153 154 155 156 157 158 159 |
# File 'lib/semantic_logger/base.rb', line 150 def (*) = self. # Check for nil tags if Thread.current[:semantic_logger_tags] = ? + : end yield ensure Thread.current[:semantic_logger_tags] = end |