Skip to content

Instantly share code, notes, and snippets.

@jvmvik
Created August 31, 2022 13:40
Show Gist options
  • Save jvmvik/86d286abd3400112c6b30cc5a0b16fa4 to your computer and use it in GitHub Desktop.
Save jvmvik/86d286abd3400112c6b30cc5a0b16fa4 to your computer and use it in GitHub Desktop.
Ruby log simple colorful implementation
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