Class: LanguageOperator::CLI::Formatters::LogStyle
- Inherits:
-
Object
- Object
- LanguageOperator::CLI::Formatters::LogStyle
- Defined in:
- lib/language_operator/cli/formatters/log_style.rb
Overview
Centralized configuration for log level icons and colors
Single source of truth for all logging/notification output across the codebase. This ensures consistent styling and makes it easy to customize icons and colors for all log levels in one place.
Constant Summary collapse
- STYLES =
Style configuration for each log level
{ debug: { icon: '☢', color: :dim }, info: { icon: '⚬', color: :cyan }, success: { icon: '✔', color: :green }, warn: { icon: '⚠', color: :yellow }, error: { icon: '✗', color: :red } }.freeze
Class Method Summary collapse
-
.ansi_icon(level) ⇒ String
Get ANSI color code for a level (for Logger compatibility).
-
.color(level) ⇒ Symbol
Get the color for a log level.
-
.detect_level_from_message(message) ⇒ Symbol
Detect log level from message content.
-
.emoji_to_level(emoji) ⇒ Symbol
Convert emoji to log level symbol.
-
.format(level, message, pastel) ⇒ String
Format a message with icon and color for the given log level.
-
.icon(level) ⇒ String
Get the icon for a log level.
-
.styled_icon(level, pastel) ⇒ String
Get a styled icon with ANSI color codes embedded.
Class Method Details
.ansi_icon(level) ⇒ String
Get ANSI color code for a level (for Logger compatibility)
119 120 121 122 123 124 125 126 |
# File 'lib/language_operator/cli/formatters/log_style.rb', line 119 def ansi_icon(level) level_sym = level.to_s.downcase.to_sym style = STYLES[level_sym] || STYLES[:info] icon = style[:icon] color_code = ansi_color_code(style[:color]) "#{color_code}#{icon}\e[0m" end |
.color(level) ⇒ Symbol
Get the color for a log level
59 60 61 |
# File 'lib/language_operator/cli/formatters/log_style.rb', line 59 def color(level) STYLES.dig(level, :color) || STYLES[:info][:color] end |
.detect_level_from_message(message) ⇒ Symbol
Detect log level from message content
Useful for inferring log level from message text when not explicitly provided.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/language_operator/cli/formatters/log_style.rb', line 79 def () case when /error|fail|✗|❌/i :error when /warn|⚠/i :warn when /completed|finished|success|✔|✅/i :success when /debug|☢/i :debug else :info end end |
.emoji_to_level(emoji) ⇒ Symbol
Convert emoji to log level symbol
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/language_operator/cli/formatters/log_style.rb', line 98 def emoji_to_level(emoji) case emoji when /[☰ℹ]/ :info when /[☢🔍]/ :debug when /⚠/ :warn when /[✗❌]/ :error when /[✔✅]/ :success else :info end end |
.format(level, message, pastel) ⇒ String
Format a message with icon and color for the given log level
39 40 41 42 43 44 45 |
# File 'lib/language_operator/cli/formatters/log_style.rb', line 39 def format(level, , pastel) style = STYLES[level] || STYLES[:info] icon = style[:icon] color = style[:color] pastel.send(color, "#{icon} #{}") end |