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.9"

Class Method Summary collapse

Class Method Details

.debug(message, args = nil) ⇒ Object



41
42
43
# File 'lib/inform.rb', line 41

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

.error(message, args = nil) ⇒ Object



73
74
75
# File 'lib/inform.rb', line 73

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

.info(message, args = nil) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/inform.rb', line 45

def info(message, args=nil)

  if block_given?
    start = Time.now
    smart_newlines = thread_prefix.nil?
    if smart_newlines
      log(:info, ">>> " + color_args(message, args, GREEN) + " : ", :no_newline => true)
    end

    ret = yield

    elapsed = Time.now - start
    completion = elapsed > 0.01 ? "Done. (#{sprintf '%.2f', elapsed}s)" : 'Done.'
    if smart_newlines
      log(:info, color(completion, GREEN), :continue_line => true, :prefix => '>>> ')
    else
      log(:info, "*** " + color(message, GREEN) + ' : ' + color(completion, GREEN))
    end
    ret
  else
    log(:info, "*** " + color_args(message, args, GREEN))
  end
end

.levelObject



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

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

.level=(_level) ⇒ Object



36
37
38
39
# File 'lib/inform.rb', line 36

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

.thread_prefixObject



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

def thread_prefix
  Thread.current[:inform_prefix]
end

.thread_prefix=(prefix) ⇒ Object



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

def thread_prefix= prefix
  Thread.current[:inform_prefix] = prefix
end

.warning(message, args = nil) ⇒ Object



69
70
71
# File 'lib/inform.rb', line 69

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