Class: Inform

Inherits:
Object
  • Object
show all
Defined in:
lib/inform.rb,
lib/inform/version.rb

Constant Summary collapse

CLEAR =
"\e[0m"
BOLD =
"\e[1m"
UNDERLINE =
"\e[4m"
BLACK =
"\e[30m"
RED =
"\e[31m"
GREEN =
"\e[32m"
YELLOW =
"\e[33m"
BLUE =
"\e[34m"
MAGENTA =
"\e[35m"
CYAN =
"\e[36m"
WHITE =
"\e[37m"
DEFAULT_LOG_LEVEL =
:info
LOG_LEVELS =
[:debug, :info, :warning, :error]
VERSION =
"0.0.5"

Class Method Summary collapse

Class Method Details

.debug(message, args = nil) ⇒ Object



33
34
35
# File 'lib/inform.rb', line 33

def debug(message, args=nil)
  log(:debug, "    " + color_args(message, args, CYAN))
end

.error(message, args = nil) ⇒ Object



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

def error(message, args=nil)
  log(:error, color('ERROR', RED, BOLD) + ': ' + color_args(message, args, RED))
end

.info(message, args = nil) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/inform.rb', line 37

def info(message, args=nil)
  if block_given?
    log(:info, ">>> " + color_args(message, args, GREEN) + " : ", :no_newline => true)
    ret = yield
    log(:info, color('Done.', GREEN), :continue_line => true, :prefix => '>>> ')
    ret
  else
    log(:info, "*** " + color_args(message, args, GREEN))
  end
end

.levelObject



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

def level
  @level.nil? ? DEFAULT_LOG_LEVEL : @level
end

.level=(_level) ⇒ Object



28
29
30
31
# File 'lib/inform.rb', line 28

def level= _level
  raise "Unrecognized log level #{_level} (should be one of #{LOG_LEVELS.join(', ')})" unless LOG_LEVELS.include?(_level)
  @level = _level
end

.warning(message, args = nil) ⇒ Object



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

def warning(message, args=nil)
  log(:warning, color('WARNING', YELLOW, BOLD) + ': ' + color_args(message, args, YELLOW))
end