Class: Logger
- Inherits:
-
Object
- Object
- Logger
- Defined in:
- lib/esearchy/logger.rb
Instance Attribute Summary collapse
-
#device ⇒ Object
Returns the value of attribute device.
-
#level ⇒ Object
Returns the value of attribute level.
Instance Method Summary collapse
- #clean(msg) ⇒ Object
- #close ⇒ Object
-
#initialize(level, output) ⇒ Logger
constructor
A new instance of Logger.
- #puts(msg) ⇒ Object
Constructor Details
#initialize(level, output) ⇒ Logger
Returns a new instance of Logger.
3 4 5 6 7 8 9 10 11 |
# File 'lib/esearchy/logger.rb', line 3 def initialize(level, output) @level = level if output.class == IO @device = output else @device = File.new(output, "a") end @device.sync = true end |
Instance Attribute Details
#device ⇒ Object
Returns the value of attribute device.
12 13 14 |
# File 'lib/esearchy/logger.rb', line 12 def device @device end |
#level ⇒ Object
Returns the value of attribute level.
12 13 14 |
# File 'lib/esearchy/logger.rb', line 12 def level @level end |
Instance Method Details
#clean(msg) ⇒ Object
24 25 26 |
# File 'lib/esearchy/logger.rb', line 24 def clean(msg) msg.match(/\n|\r/) != nil ? msg.strip! : msg end |
#close ⇒ Object
28 29 30 |
# File 'lib/esearchy/logger.rb', line 28 def close @device.close if @open end |
#puts(msg) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/esearchy/logger.rb', line 14 def puts(msg) if @level > 1 begin @device.puts clean(msg) + "\n" rescue Raise "Something went Wrong writing to [file|IO]" end end end |