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, white: 97 ].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
20 21 22 |
# File 'lib/stealth/logger.rb', line 20 def self.color_code(code) COLORS.fetch(code) { raise(ArgumentError, "Color #{code} not supported.") } end |
.colorize(input, color:) ⇒ Object
24 25 26 |
# File 'lib/stealth/logger.rb', line 24 def self.colorize(input, color:) "\e[#{color_code(color)}m#{input}\e[0m" end |
.log(topic:, message:) ⇒ Object Also known as: l
28 29 30 31 32 |
# File 'lib/stealth/logger.rb', line 28 def self.log(topic:, message:) unless ENV['STEALTH_ENV'] == 'test' puts "TID-#{Stealth.tid} #{print_topic(topic)} #{}" end end |
.print_topic(topic) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/stealth/logger.rb', line 34 def self.print_topic(topic) topic_string = "[#{topic}]" color = case topic.to_sym when :primary_session :green when :previous_session, :back_to_session :yellow when :interrupt :magenta when :facebook, :twilio, :bandwidth :blue when :smooch :magenta when :alexa, :voice, :twilio_voice, :unrecognized_message :light_cyan when :nlp :cyan when :catch_all, :err :red when :user :white else :gray end colorize(topic_string, color: color) end |