Class: Nav::Logger::ConsoleLogger
- Inherits:
-
BaseLogger
- Object
- BaseLogger
- Nav::Logger::ConsoleLogger
- Defined in:
- lib/nav/logger/console_logger.rb
Constant Summary collapse
- CODEMAP =
Mapping of color/style names to ANSI control values
{ normal: 0, bold: 1, black: 30, red: 31, green: 32, yellow: 33, blue: 34, magenta: 35, cyan: 36, white: 37 }
- LEVELMAP =
Map of log levels to colors
{ "FATAL" => :red, "ERROR" => :red, "WARN" => :yellow, "INFO" => :green, # default color "DEBUG" => :cyan }
Instance Attribute Summary
Attributes inherited from BaseLogger
Class Method Summary collapse
-
.post_with_time(tag, map, time) ⇒ Object
Adds colorized loigging.
Instance Method Summary collapse
-
#initialize ⇒ ConsoleLogger
constructor
A new instance of ConsoleLogger.
Methods inherited from BaseLogger
#debug, #error, #fatal, #info, #level, #level=, #level_name, #level_symbol, #log_tag, #post, #warn
Constructor Details
#initialize ⇒ ConsoleLogger
Returns a new instance of ConsoleLogger.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/nav/logger/console_logger.rb', line 27 def initialize @fluent_logger = Fluent::Logger::ConsoleLogger.open STDOUT # Adds colorized loigging def @fluent_logger.post_with_time(tag, map, time) a = [time.strftime(@time_format), " ", tag, ":"] map.each_pair { |k,v| a << " #{k}=" a << JSON.dump(v) } color = LEVELMAP[map[:level]] || :green a.unshift "\e[#{CODEMAP[color]}m" a << "\e[#{CODEMAP[:normal]}m" post_text a.join true end end |
Class Method Details
.post_with_time(tag, map, time) ⇒ Object
Adds colorized loigging
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/nav/logger/console_logger.rb', line 31 def @fluent_logger.post_with_time(tag, map, time) a = [time.strftime(@time_format), " ", tag, ":"] map.each_pair { |k,v| a << " #{k}=" a << JSON.dump(v) } color = LEVELMAP[map[:level]] || :green a.unshift "\e[#{CODEMAP[color]}m" a << "\e[#{CODEMAP[:normal]}m" post_text a.join true end |