Class: Inform
- Inherits:
-
Object
- Object
- Inform
- 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
- .debug(message, args = nil) ⇒ Object
- .error(message, args = nil) ⇒ Object
- .info(message, args = nil) ⇒ Object
- .level ⇒ Object
- .level=(_level) ⇒ Object
- .thread_prefix ⇒ Object
- .thread_prefix=(prefix) ⇒ Object
- .warning(message, args = nil) ⇒ Object
Class Method Details
.debug(message, args = nil) ⇒ Object
41 42 43 |
# File 'lib/inform.rb', line 41 def debug(, args=nil) log(:debug, " " + color_args(, args, CYAN)) end |
.error(message, args = nil) ⇒ Object
73 74 75 |
# File 'lib/inform.rb', line 73 def error(, args=nil) log(:error, color('ERROR', RED, BOLD) + ': ' + color_args(, 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(, args=nil) if block_given? start = Time.now smart_newlines = thread_prefix.nil? if smart_newlines log(:info, ">>> " + color_args(, 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(, GREEN) + ' : ' + color(completion, GREEN)) end ret else log(:info, "*** " + color_args(, args, GREEN)) end end |
.level ⇒ Object
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_prefix ⇒ Object
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 |