Class: Cybertrain::Logger
- Inherits:
-
Object
- Object
- Cybertrain::Logger
- Defined in:
- cybertrain/logger.rb
Overview
A leveled logger writing one line per message to standard output (or
to the io it was given): debug, info, warn, error, fatal.
The line’s shape is the file’s header comment; logger is
the one the framework logs through.
Defined Under Namespace
Classes: Scope
Class Method Summary collapse
-
.current_scope ⇒ Scope
This thread’s Scope, NO_SCOPE when it has none.
-
.json_lines ⇒ Boolean
Whether lines are JSON objects (
c.log_format = :json, installed by Runtime.apply) rather than text. -
.json_lines=(on) ⇒ nil
Turns JSON lines on or off.
-
.reset_scope ⇒ nil
Empties this thread’s slot: the thread is back to NO_SCOPE.
-
.swap_scope(scope) ⇒ Scope
Makes
scopethis thread’s Scope (the slot holds nil for NO_SCOPE) and answers the one it replaces.
Instance Method Summary collapse
-
#tagged(*tags) ⇒ Object
Adds
tagsto every line logged on this thread while the block runs, after the request’s own, and restores the previous tags when it ends, also when it raises (spec section 12.4).
Class Method Details
.current_scope ⇒ Scope
This thread’s Scope, NO_SCOPE when it has none.
140 141 142 143 |
# File 'cybertrain/logger.rb', line 140 def self.current_scope value = Thread.current[SCOPE_KEY] value.nil? ? NO_SCOPE : value end |
.json_lines ⇒ Boolean
Whether lines are JSON objects (c.log_format = :json, installed by
Runtime.apply) rather than text.
190 191 192 |
# File 'cybertrain/logger.rb', line 190 def self.json_lines @json_lines end |
.json_lines=(on) ⇒ nil
Turns JSON lines on or off.
198 199 200 201 |
# File 'cybertrain/logger.rb', line 198 def self.json_lines=(on) @json_lines = on nil end |
.reset_scope ⇒ nil
Empties this thread’s slot: the thread is back to NO_SCOPE. The test harness calls it around every case (spec section 20).
161 162 163 164 |
# File 'cybertrain/logger.rb', line 161 def self.reset_scope Thread.current[SCOPE_KEY] = nil nil end |
.swap_scope(scope) ⇒ Scope
Makes scope this thread’s Scope (the slot holds nil for
NO_SCOPE) and answers the one it replaces. Whoever runs work on a
thread swaps its Scope in and the answered one back in an ensure.
151 152 153 154 155 |
# File 'cybertrain/logger.rb', line 151 def self.swap_scope(scope) previous = Logger.current_scope Thread.current[SCOPE_KEY] = scope.equal?(NO_SCOPE) ? nil : scope previous end |
Instance Method Details
#tagged(*tags) ⇒ Object
Adds tags to every line logged on this thread while the block
runs, after the request’s own, and restores the previous tags when
it ends, also when it raises (spec section 12.4). Every Logger on
the thread sees them: they live in the thread’s Scope.
Answers the block’s value. There is no block-less form.
511 |
# File 'cybertrain/logger.rb', line 511 def tagged(*) = Logger.tagged_during() { yield } |