Class: Senna::Logger
- Inherits:
-
Object
- Object
- Senna::Logger
- Defined in:
- lib/senna/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
19 20 21 |
# File 'lib/senna/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/senna/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 |
# File 'lib/senna/logger.rb', line 27 def self.log(topic:, message:) puts "#{print_topic(topic)} #{}" end |
.print_topic(topic) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/senna/logger.rb', line 31 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 :facebook, :twilio, :bandwidth :blue when :smooch :magenta when :alexa :light_cyan when :catch_all :red when :user :white else :gray end colorize(topic_string, color: color) end |