Class: Stealth::Logger
- Inherits:
-
Object
- Object
- Stealth::Logger
- Defined in:
- lib/stealth/logger.rb
Constant Summary collapse
- COLORS =
::Hash[ black: 30, red: 31, green: 32, yellow: 33, blue: 34, magenta: 35, cyan: 36, gray: 37, light_cyan: 96 ].freeze
Class Method Summary collapse
- .color_code(code) ⇒ Object
- .colorize(input, color:) ⇒ Object
- .log(topic:, message:) ⇒ Object (also: l)
- .print_topic(topic) ⇒ Object
Class Method Details
.color_code(code) ⇒ Object
19 20 21 |
# File 'lib/stealth/logger.rb', line 19 def self.color_code(code) COLORS.fetch(code) { raise(ArgumentError, "Color #{code} not supported.") } end |
.colorize(input, color:) ⇒ Object
23 24 25 |
# File 'lib/stealth/logger.rb', line 23 def self.colorize(input, color:) "\e[#{color_code(color)}m#{input}\e[0m" end |
.log(topic:, message:) ⇒ Object Also known as: l
27 28 29 30 31 |
# File 'lib/stealth/logger.rb', line 27 def self.log(topic:, message:) unless ENV['STEALTH_ENV'] == 'test' puts "#{print_topic(topic)} #{}" end end |
.print_topic(topic) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/stealth/logger.rb', line 33 def self.print_topic(topic) topic_string = "[#{topic}]" case topic.to_sym when :session colorize(topic_string, color: :green) when :previous_session colorize(topic_string, color: :yellow) when :facebook, :twilio colorize(topic_string, color: :blue) when :smooch colorize(topic_string, color: :magenta) when :alexa colorize(topic_string, color: :light_cyan) when :catch_all colorize(topic_string, color: :red) else colorize(topic_string, color: :gray) end end |