Module: Log
- Extended by:
- Term::ANSIColor
- Defined in:
- lib/rbbt/util/log.rb,
lib/rbbt/util/log/progress.rb,
lib/rbbt/util/log/progress/util.rb,
lib/rbbt/util/log/progress/report.rb
Defined Under Namespace
Classes: ProgressBar
Constant Summary collapse
- SEVERITY_COLOR =
.collect{|e| “033[#{e}”}
[reset, cyan, green, magenta, blue, yellow, red]
- HIGHLIGHT =
"\033[1m"- LOG_MUTEX =
Mutex.new
- LAST =
"log"
Class Attribute Summary collapse
-
.logfile ⇒ Object
Returns the value of attribute logfile.
-
.nocolor ⇒ Object
Returns the value of attribute nocolor.
-
.severity ⇒ Object
Returns the value of attribute severity.
-
.tty_size ⇒ Object
Returns the value of attribute tty_size.
Class Method Summary collapse
- .clear_line(out = STDOUT) ⇒ Object
- .color(severity, str = nil, reset = false) ⇒ Object
- .debug(message = nil, &block) ⇒ Object
- .error(message = nil, &block) ⇒ Object
- .exception(e) ⇒ Object
- .get_level(level) ⇒ Object
- .high(message = nil, &block) ⇒ Object
- .highlight(str = nil) ⇒ Object
- .info(message = nil, &block) ⇒ Object
- .log(message = nil, severity = MEDIUM, &block) ⇒ Object
- .log_obj_fingerprint(obj, level, file = $stdout) ⇒ Object
- .log_obj_inspect(obj, level, file = $stdout) ⇒ Object
- .low(message = nil, &block) ⇒ Object
- .medium(message = nil, &block) ⇒ Object
- .reset_color ⇒ Object
- .return_line ⇒ Object
- .uncolor(str) ⇒ Object
- .warn(message = nil, &block) ⇒ Object
- .with_severity(level) ⇒ Object
Class Attribute Details
.logfile ⇒ Object
Returns the value of attribute logfile.
33 34 35 |
# File 'lib/rbbt/util/log.rb', line 33 def logfile @logfile end |
.nocolor ⇒ Object
Returns the value of attribute nocolor.
33 34 35 |
# File 'lib/rbbt/util/log.rb', line 33 def nocolor @nocolor end |
.severity ⇒ Object
Returns the value of attribute severity.
33 34 35 |
# File 'lib/rbbt/util/log.rb', line 33 def severity @severity end |
.tty_size ⇒ Object
Returns the value of attribute tty_size.
33 34 35 |
# File 'lib/rbbt/util/log.rb', line 33 def tty_size @tty_size end |
Class Method Details
.clear_line(out = STDOUT) ⇒ Object
82 83 84 |
# File 'lib/rbbt/util/log.rb', line 82 def self.clear_line(out = STDOUT) out.puts Log.return_line << " " * (Log.tty_size || 80) << Log.return_line unless nocolor end |
.color(severity, str = nil, reset = false) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/rbbt/util/log.rb', line 66 def self.color(severity, str = nil, reset = false) return str || "" if nocolor color = reset ? Term::ANSIColor.reset : "" color << SEVERITY_COLOR[severity] if Fixnum === severity color << Term::ANSIColor.send(severity) if Symbol === severity and Term::ANSIColor.respond_to? severity if str.nil? color else color + str.to_s + self.color(0) end end |
.debug(message = nil, &block) ⇒ Object
153 154 155 |
# File 'lib/rbbt/util/log.rb', line 153 def self.debug( = nil, &block) log(, DEBUG, &block) end |
.error(message = nil, &block) ⇒ Object
177 178 179 |
# File 'lib/rbbt/util/log.rb', line 177 def self.error( = nil, &block) log(, ERROR, &block) end |
.exception(e) ⇒ Object
181 182 183 184 185 186 |
# File 'lib/rbbt/util/log.rb', line 181 def self.exception(e) stack = caller error("#{Log.color :error, "EXCEPTION:"} " << stack.first) error([e.class.to_s, e.].compact * ": ") error("BACKTRACE:\n" + e.backtrace * "\n") end |
.get_level(level) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/rbbt/util/log.rb', line 17 def self.get_level(level) case level when Fixnum level when String begin Log.const_get(level.upcase) rescue Log.exception $! end when Symbol get_level(level.to_s) end || 0 end |
.high(message = nil, &block) ⇒ Object
165 166 167 |
# File 'lib/rbbt/util/log.rb', line 165 def self.high( = nil, &block) log(, HIGH, &block) end |
.highlight(str = nil) ⇒ Object
86 87 88 89 90 91 92 93 94 |
# File 'lib/rbbt/util/log.rb', line 86 def self.highlight(str = nil) if str.nil? return "" if nocolor HIGHLIGHT else return str if nocolor HIGHLIGHT + str + color(0) end end |
.info(message = nil, &block) ⇒ Object
169 170 171 |
# File 'lib/rbbt/util/log.rb', line 169 def self.info( = nil, &block) log(, INFO, &block) end |
.log(message = nil, severity = MEDIUM, &block) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/rbbt/util/log.rb', line 98 def self.log( = nil, severity = MEDIUM, &block) return if severity < self.severity ||= block.call if block_given? return if .nil? time = Time.now.strftime("%m/%d/%y-%H:%M:%S") sev_str = severity.to_s prefix = time << "[" << color(severity) << sev_str << color(0)<<"]" = "" << highlight << << color(0) if severity >= INFO str = prefix << " " << LOG_MUTEX.synchronize do STDERR.puts str Log::LAST.replace "log" logfile.puts str unless logfile.nil? nil end end |
.log_obj_fingerprint(obj, level, file = $stdout) ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/rbbt/util/log.rb', line 136 def self.log_obj_fingerprint(obj, level, file = $stdout) stack = caller line = nil while line.nil? or line =~ /util\/log\.rb/ and stack.any? line = stack.shift end line ||= caller.first level = Log.get_level level name = Log::SEVERITY_NAMES[level] + ": " Log.log Log.color(level, name, true) << line, level Log.log "", level Log.log Log.color(level, "=> ", true) << Misc.fingerprint(obj), level Log.log "", level end |
.log_obj_inspect(obj, level, file = $stdout) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/rbbt/util/log.rb', line 119 def self.log_obj_inspect(obj, level, file = $stdout) stack = caller line = nil while line.nil? or line =~ /util\/log\.rb/ and stack.any? line = stack.shift end line ||= caller.first level = Log.get_level level name = Log::SEVERITY_NAMES[level] + ": " Log.log Log.color(level, name, true) << line, level Log.log "", level Log.log Log.color(level, "=> ", true) << obj.inspect, level Log.log "", level end |
.low(message = nil, &block) ⇒ Object
157 158 159 |
# File 'lib/rbbt/util/log.rb', line 157 def self.low( = nil, &block) log(, LOW, &block) end |
.medium(message = nil, &block) ⇒ Object
161 162 163 |
# File 'lib/rbbt/util/log.rb', line 161 def self.medium( = nil, &block) log(, MEDIUM, &block) end |
.reset_color ⇒ Object
62 63 64 |
# File 'lib/rbbt/util/log.rb', line 62 def self.reset_color reset end |
.return_line ⇒ Object
78 79 80 |
# File 'lib/rbbt/util/log.rb', line 78 def self.return_line nocolor ? "" : "\033[1A" end |
.uncolor(str) ⇒ Object
58 59 60 |
# File 'lib/rbbt/util/log.rb', line 58 def self.uncolor(str) Term::ANSIColor.uncolor(str) end |
.warn(message = nil, &block) ⇒ Object
173 174 175 |
# File 'lib/rbbt/util/log.rb', line 173 def self.warn( = nil, &block) log(, WARN, &block) end |