Class: SwitchTower::Logger
- Inherits:
-
Object
- Object
- SwitchTower::Logger
- Defined in:
- lib/switchtower/logger.rb
Overview
:nodoc:
Constant Summary collapse
- IMPORTANT =
0
- INFO =
1
- DEBUG =
2
- TRACE =
3
Instance Attribute Summary collapse
-
#level ⇒ Object
Returns the value of attribute level.
Instance Method Summary collapse
- #close ⇒ Object
- #debug(message, line_prefix = nil) ⇒ Object
- #important(message, line_prefix = nil) ⇒ Object
- #info(message, line_prefix = nil) ⇒ Object
-
#initialize(options = {}) ⇒ Logger
constructor
A new instance of Logger.
- #log(level, message, line_prefix = nil) ⇒ Object
- #trace(message, line_prefix = nil) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Logger
Returns a new instance of Logger.
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/switchtower/logger.rb', line 10 def initialize(={}) output = [:output] || STDERR case when output.respond_to?(:puts) @device = output else @device = File.open(output.to_str, "a") @needs_close = true end @options = @level = 0 end |
Instance Attribute Details
#level ⇒ Object
Returns the value of attribute level.
3 4 5 |
# File 'lib/switchtower/logger.rb', line 3 def level @level end |
Instance Method Details
#close ⇒ Object
24 25 26 |
# File 'lib/switchtower/logger.rb', line 24 def close @device.close if @needs_close end |
#debug(message, line_prefix = nil) ⇒ Object
48 49 50 |
# File 'lib/switchtower/logger.rb', line 48 def debug(, line_prefix=nil) log(DEBUG, , line_prefix) end |
#important(message, line_prefix = nil) ⇒ Object
40 41 42 |
# File 'lib/switchtower/logger.rb', line 40 def important(, line_prefix=nil) log(IMPORTANT, , line_prefix) end |
#info(message, line_prefix = nil) ⇒ Object
44 45 46 |
# File 'lib/switchtower/logger.rb', line 44 def info(, line_prefix=nil) log(INFO, , line_prefix) end |
#log(level, message, line_prefix = nil) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/switchtower/logger.rb', line 28 def log(level, , line_prefix=nil) if level <= self.level if line_prefix .split(/\r?\n/).each do |line| @device.print "[#{line_prefix}] #{line.strip}\n" end else @device.puts .strip end end end |
#trace(message, line_prefix = nil) ⇒ Object
52 53 54 |
# File 'lib/switchtower/logger.rb', line 52 def trace(, line_prefix=nil) log(TRACE, , line_prefix) end |