Module: LogBot
- Defined in:
- lib/drakkon/lib/logbot.rb
Overview
Log Helper
Class Method Summary collapse
-
.clock_time ⇒ Object
From Rack Time.
- .color_level(level) ⇒ Object
- .debug(name, message = nil, level = :debug) ⇒ Object
- .do(name, message = nil, level = nil) ⇒ Object
- .error(name, message = nil, level = :error) ⇒ Object
- .fatal(name, message = nil, level = :fatal) ⇒ Object
- .info(name, message = nil, level = :info) ⇒ Object
- .measure ⇒ Object
- .output(name, message, level, duration = nil) ⇒ Object
-
.settings ⇒ Object
For Amazing Print.
- .warn(name, message = nil, level = :warn) ⇒ Object
Class Method Details
.clock_time ⇒ Object
From Rack Time
83 84 85 |
# File 'lib/drakkon/lib/logbot.rb', line 83 def self.clock_time Process.clock_gettime(Process::CLOCK_MONOTONIC) end |
.color_level(level) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/drakkon/lib/logbot.rb', line 27 def self.color_level(level) case level when :debug level.to_s.upcase.pastel(:bright_cyan) when :info level.to_s.upcase.pastel(:cyan) when :warn level.to_s.upcase.pastel(:yellow) when :error level.to_s.upcase.pastel(:bright_red) when :fatal level.to_s.upcase.pastel(:red) end end |
.debug(name, message = nil, level = :debug) ⇒ Object
46 47 48 |
# File 'lib/drakkon/lib/logbot.rb', line 46 def self.debug(name, = nil, level = :debug) output(name, , level) end |
.do(name, message = nil, level = nil) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/drakkon/lib/logbot.rb', line 62 def self.do(name, = nil, level = nil) began_at = clock_time level ||= :info result = yield duration = (clock_time - began_at).round(3) output(name, , level, duration) result end |
.error(name, message = nil, level = :error) ⇒ Object
54 55 56 |
# File 'lib/drakkon/lib/logbot.rb', line 54 def self.error(name, = nil, level = :error) output(name, , level) end |
.fatal(name, message = nil, level = :fatal) ⇒ Object
58 59 60 |
# File 'lib/drakkon/lib/logbot.rb', line 58 def self.fatal(name, = nil, level = :fatal) output(name, , level) end |
.info(name, message = nil, level = :info) ⇒ Object
42 43 44 |
# File 'lib/drakkon/lib/logbot.rb', line 42 def self.info(name, = nil, level = :info) output(name, , level) end |
.measure ⇒ Object
75 76 77 78 79 80 |
# File 'lib/drakkon/lib/logbot.rb', line 75 def self.measure began_at = clock_time result = yield duration = (clock_time - began_at).round(3) [result, duration] end |
.output(name, message, level, duration = nil) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/drakkon/lib/logbot.rb', line 8 def self.output(name, , level, duration = nil) time = Time.now.strftime('%I:%M:%S').pastel(:bright_black) output = time output += " #{color_level(level)}" output += " - #{name.to_s.pastel(:bright_blue)} " output += "(#{duration.round(2)}) ".pastel(:magenta) if duration output += ' ' if output += case when String then else .ai(settings) end end puts output unless ENV['TESTING'] end |
.settings ⇒ Object
For Amazing Print
4 5 6 |
# File 'lib/drakkon/lib/logbot.rb', line 4 def self.settings { ruby19_syntax: true, multiline: false } end |
.warn(name, message = nil, level = :warn) ⇒ Object
50 51 52 |
# File 'lib/drakkon/lib/logbot.rb', line 50 def self.warn(name, = nil, level = :warn) output(name, , level) end |