Class: SMS::Logger
- Inherits:
-
Object
- Object
- SMS::Logger
- Defined in:
- lib/rubysms/logger.rb
Instance Method Summary collapse
- #event(str, type = :info) ⇒ Object
- #event_with_time(str, *rest) ⇒ Object
-
#initialize(stream = $stdout) ⇒ Logger
constructor
A new instance of Logger.
Constructor Details
#initialize(stream = $stdout) ⇒ Logger
Returns a new instance of Logger.
6 7 8 |
# File 'lib/rubysms/logger.rb', line 6 def initialize(stream=$stdout) @stream = stream end |
Instance Method Details
#event(str, type = :info) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rubysms/logger.rb', line 10 def event(str, type=:info) # arrays or strings are fine. quack! str = str.join("\n") if str.respond_to?(:join) # each item in the log is prefixed by a four-char # coloured prefix block, to help scanning by eye prefix_text = LogPrefix[type] || type.to_s prefix = colored(prefix_text, type) # the first line of the message is indented by # the prefix, so indent subsequent lines by an # equal amount of space, to keep them lined up indent = colored((" " * prefix_text.length), type) + " " @stream.puts prefix + " " + str.to_s.gsub("\n", "\n#{indent}") # flush immediately, to prevent # the log being backend up @stream.flush end |
#event_with_time(str, *rest) ⇒ Object
31 32 33 |
# File 'lib/rubysms/logger.rb', line 31 def event_with_time(str, *rest) event("#{time_log(Time.now)} #{str}", *rest) end |