Module: Log
- Defined in:
- lib/rbbt/util/log.rb
Constant Summary collapse
- DEBUG =
0
- LOW =
1
- MEDIUM =
2
- HIGH =
3
- INFO =
4
- WARN =
5
- ERROR =
6
- SEVERITY_COLOR =
[WHITE, GREEN, YELLOW, RED, GREEN, YELLOW, ERROR].collect{|e| "\033[#{e}"}
Class Attribute Summary collapse
-
.logfile ⇒ Object
Returns the value of attribute logfile.
-
.severity ⇒ Object
Returns the value of attribute severity.
Class Method Summary collapse
- .debug(message = nil, &block) ⇒ Object
- .error(message = nil, &block) ⇒ Object
- .high(message = nil, &block) ⇒ Object
- .info(message = nil, &block) ⇒ Object
- .log(message = nil, severity = MEDIUM, &block) ⇒ Object
- .low(message = nil, &block) ⇒ Object
- .medium(message = nil, &block) ⇒ Object
- .warn(message = nil, &block) ⇒ Object
Class Attribute Details
.logfile ⇒ Object
Returns the value of attribute logfile.
12 13 14 |
# File 'lib/rbbt/util/log.rb', line 12 def logfile @logfile end |
.severity ⇒ Object
Returns the value of attribute severity.
12 13 14 |
# File 'lib/rbbt/util/log.rb', line 12 def severity @severity end |
Class Method Details
.debug(message = nil, &block) ⇒ Object
39 40 41 |
# File 'lib/rbbt/util/log.rb', line 39 def self.debug( = nil, &block) log(, DEBUG, &block) end |
.error(message = nil, &block) ⇒ Object
63 64 65 |
# File 'lib/rbbt/util/log.rb', line 63 def self.error( = nil, &block) log(, ERROR, &block) end |
.high(message = nil, &block) ⇒ Object
51 52 53 |
# File 'lib/rbbt/util/log.rb', line 51 def self.high( = nil, &block) log(, HIGH, &block) end |
.info(message = nil, &block) ⇒ Object
55 56 57 |
# File 'lib/rbbt/util/log.rb', line 55 def self.info( = nil, &block) log(, INFO, &block) end |
.log(message = nil, severity = MEDIUM, &block) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rbbt/util/log.rb', line 24 def self.log( = nil, severity = MEDIUM, &block) ||= block return if .nil? severity_color = SEVERITY_COLOR[severity] font_color = {true => WHITE, false => DARK}[severity >= INFO] return if severity < self.severity = .call if Proc === return if .nil? or .empty? str = "\033[0;37m#{Time.now.strftime("[%m/%d/%y-%H:%M:%S]")}#{severity_color}[#{severity.to_s}]\033[0m:#{font_color} " << .strip << "\033[0m" STDERR.puts str logfile.puts str unless logfile.nil? end |
.low(message = nil, &block) ⇒ Object
43 44 45 |
# File 'lib/rbbt/util/log.rb', line 43 def self.low( = nil, &block) log(, LOW, &block) end |
.medium(message = nil, &block) ⇒ Object
47 48 49 |
# File 'lib/rbbt/util/log.rb', line 47 def self.medium( = nil, &block) log(, MEDIUM, &block) end |
.warn(message = nil, &block) ⇒ Object
59 60 61 |
# File 'lib/rbbt/util/log.rb', line 59 def self.warn( = nil, &block) log(, WARN, &block) end |