Created
August 31, 2022 13:40
-
-
Save jvmvik/86d286abd3400112c6b30cc5a0b16fa4 to your computer and use it in GitHub Desktop.
Ruby log simple colorful implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Logging | |
ESCAPES = { :green => "\033[32m", | |
:yellow => "\033[33m", | |
:red => "\033[31m", | |
:reset => "\033[0m" } | |
def info(message) | |
emit(:message => message, :color => :green) | |
end | |
def warn(message) | |
emit(:message => message, :color => :yellow) | |
end | |
def error(message) | |
emit(:message => message, :color => :red) | |
end | |
def emit(opts={}) | |
color = opts[:color] | |
message = opts[:message] | |
print ESCAPES[color] | |
print message | |
print ESCAPES[:reset] | |
print "\n" | |
end | |
end | |
include Logger | |
info("info message is green") | |
warn("warning message is orange") | |
error("error message is red") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment