Class: Rubee::Stdout

Inherits:
Object
  • Object
show all
Defined in:
lib/rubee/logger.rb

Class Method Summary collapse

Class Method Details

.critical(message:, **options, &block) ⇒ Object



40
41
42
# File 'lib/rubee/logger.rb', line 40

def critical(message:, **options, &block)
  log(:critical, message, options, &block)
end

.debug(object:, **options, &block) ⇒ Object



48
49
50
# File 'lib/rubee/logger.rb', line 48

def debug(object:, **options, &block)
  log(:debug, object.inspect, options, &block)
end

.error(message:, **options, &block) ⇒ Object



36
37
38
# File 'lib/rubee/logger.rb', line 36

def error(message:, **options, &block)
  log(:error, message, options, &block)
end

.info(message:, **options, &block) ⇒ Object



44
45
46
# File 'lib/rubee/logger.rb', line 44

def info(message:, **options, &block)
  log(:info, message, options, &block)
end

.log(severity, message, options = {}, &block) ⇒ Object



72
73
74
75
76
77
78
79
80
# File 'lib/rubee/logger.rb', line 72

def log(severity, message, options = {}, &block)
  time = Time.now.strftime('%Y-%m-%d %H:%M:%S')
  if options.any?
    message = options.map { |k, v| "[#{k}: #{v}]" }.join << " #{message}"
  end
  send("print_#{severity}", "[#{time}] #{severity.upcase} #{message}")

  block&.call(message, options) if block_given?
end


68
69
70
# File 'lib/rubee/logger.rb', line 68

def print_critical(message)
  color_puts(message, color: :red, style: :blink)
end


64
65
66
# File 'lib/rubee/logger.rb', line 64

def print_debug(message)
  color_puts(message)
end


52
53
54
# File 'lib/rubee/logger.rb', line 52

def print_error(message)
  color_puts(message, color: :red)
end


56
57
58
# File 'lib/rubee/logger.rb', line 56

def print_info(message)
  color_puts(message, color: :gray)
end


60
61
62
# File 'lib/rubee/logger.rb', line 60

def print_warn(message)
  color_puts(message, color: :yellow)
end

.warn(message:, **options, &block) ⇒ Object



32
33
34
# File 'lib/rubee/logger.rb', line 32

def warn(message:, **options, &block)
  log(:warn, message, options, &block)
end