Class: AdLocalize::AdLogger
- Inherits:
-
Object
- Object
- AdLocalize::AdLogger
- Defined in:
- lib/ad_localize/ad_logger.rb
Constant Summary collapse
- SEVERITY =
{ debug: Logger::DEBUG , info: Logger::INFO, warn: Logger::WARN, error: Logger::ERROR, fatal: Logger::FATAL, unknown: Logger::UNKNOWN }
- AUTHORIZED_COLORS =
[:black, :yellow, :red, :blue, :green]
Instance Method Summary collapse
- #close ⇒ Object
- #debug! ⇒ Object
- #debug? ⇒ Boolean
-
#initialize ⇒ AdLogger
constructor
A new instance of AdLogger.
- #log(level, color, text) ⇒ Object
Constructor Details
#initialize ⇒ AdLogger
Returns a new instance of AdLogger.
6 7 8 9 |
# File 'lib/ad_localize/ad_logger.rb', line 6 def initialize @logger = Logger.new(STDOUT) @logger.level = Logger::INFO end |
Instance Method Details
#close ⇒ Object
29 30 31 |
# File 'lib/ad_localize/ad_logger.rb', line 29 def close @logger.close end |
#debug! ⇒ Object
21 22 23 |
# File 'lib/ad_localize/ad_logger.rb', line 21 def debug! @logger.level = Logger::DEBUG end |
#debug? ⇒ Boolean
25 26 27 |
# File 'lib/ad_localize/ad_logger.rb', line 25 def debug? @logger.debug? end |
#log(level, color, text) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/ad_localize/ad_logger.rb', line 11 def log(level, color, text) exit unless text and level and color level, color = [level, color].map(&:to_sym) raise "Color not supported" unless AUTHORIZED_COLORS.include? color raise "Invalid severity" unless SEVERITY.dig(level) @logger.add(SEVERITY.dig(level), text.send(color)) end |