Class: Loog::Colorful

Inherits:
Object
  • Object
show all
Defined in:
lib/loog/colorful.rb

Overview

Log decorator that adds ANSI colors to messages by severity:

require 'loog' require 'loog/colorful' log = Loog::Colorful.new(Loog::VERBOSE) log.debug('This will be dark gray') log.error('This will be red')

Debug messages are printed in dark gray, warnings in orange, and error messages in red. Info messages pass through unchanged.

Author

Yegor Bugayenko ([email protected])

Copyright

Copyright (c) 2018-2026 Yegor Bugayenko

License

MIT

Instance Method Summary collapse

Constructor Details

#initialize(log) ⇒ Colorful

Makes an instance.



24
25
26
# File 'lib/loog/colorful.rb', line 24

def initialize(log)
  @log = log
end

Instance Method Details

#debug(msg) ⇒ Object



28
29
30
# File 'lib/loog/colorful.rb', line 28

def debug(msg)
  @log.debug("\e[90m#{msg}\e[0m")
end

#debug?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/loog/colorful.rb', line 32

def debug?
  @log.debug?
end

#error(msg) ⇒ Object



52
53
54
# File 'lib/loog/colorful.rb', line 52

def error(msg)
  @log.error("\e[31m#{msg}\e[0m")
end

#error?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/loog/colorful.rb', line 56

def error?
  @log.error?
end

#info(msg) ⇒ Object



36
37
38
# File 'lib/loog/colorful.rb', line 36

def info(msg)
  @log.info(msg)
end

#info?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/loog/colorful.rb', line 40

def info?
  @log.info?
end

#warn(msg) ⇒ Object



44
45
46
# File 'lib/loog/colorful.rb', line 44

def warn(msg)
  @log.warn("\e[33m#{msg}\e[0m")
end

#warn?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/loog/colorful.rb', line 48

def warn?
  @log.warn?
end