Class: Scrubyt::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/scrubyt/logging.rb

Overview

Simple logger implementation, based on Scrubyt’s original logging style. Messages will be sent to STDERR. Logging can be limited to certain message levels by specifying them on initialization, e.g.

Scrubyt::Logger.new(:ACTION, :ERROR)  # will only log action/error messages

Defined Under Namespace

Classes: Message, MultiLineMessage

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*levels) ⇒ Logger

Returns a new instance of Logger.



63
64
65
# File 'lib/scrubyt/logging.rb', line 63

def initialize(*levels)
  @levels = levels
end

Instance Attribute Details

#output_streamObject



75
76
77
# File 'lib/scrubyt/logging.rb', line 75

def output_stream
  @output_stream || STDERR
end

Instance Method Details

#log(level, message) ⇒ Object



67
68
69
70
71
72
73
# File 'lib/scrubyt/logging.rb', line 67

def log(level, message)
  return unless logging?(level)

  message_class = message.is_a?(Array) ? MultiLineMessage : Message

  output_stream.puts message_class.new(level, message)
end