Module: Log
- Defined in:
- lib/Olib/log.rb
Overview
contextual logging
Defined Under Namespace
Modules: Preset
Class Method Summary collapse
- ._view(msg, label) ⇒ Object
- ._write(line) ⇒ Object
- .dump(*args) ⇒ Object
- .out(msg, label: :debug) ⇒ Object
- .pp(msg, label = :debug) ⇒ Object
Class Method Details
._view(msg, label) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/Olib/log.rb', line 25 def self._view(msg, label) label = [Script.current.name, label].flatten.compact.join(".") safe = msg.inspect #safe = safe.gsub("<", "<").gsub(">", ">") if safe.include?("<") and safe.include?(">") "[#{label}] #{safe}" end |
._write(line) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/Olib/log.rb', line 15 def self._write(line) if Script.current.vars.include?("--headless") or not defined?(:_respond) $stdout.write(line + "\n") elsif line.include?("<") and line.include?(">") respond(line) else _respond Preset.as(:debug, line) end end |
.dump(*args) ⇒ Object
36 37 38 |
# File 'lib/Olib/log.rb', line 36 def self.dump(*args) pp(*args) end |
.out(msg, label: :debug) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/Olib/log.rb', line 5 def self.out(msg, label: :debug) if msg.is_a?(Exception) ## pretty-print exception _write _view(msg., label) msg.backtrace.to_a.slice(0..5).each do |frame| _write _view(frame, label) end else self._write _view(msg, label) #if Script.current.vars.include?("--debug") end end |
.pp(msg, label = :debug) ⇒ Object
32 33 34 |
# File 'lib/Olib/log.rb', line 32 def self.pp(msg, label = :debug) respond _view(msg, label) end |