Class: Scribe

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

Constant Summary collapse

PROTOCOL_OPTIONS =
{ :protocol_extra_params => [false]  }

Instance Method Summary collapse

Constructor Details

#initialize(servers = "127.0.0.1:1463", category = "Ruby", add_newlines = true, options = {}) ⇒ Scribe

Created a new client instance. Accepts an optional host and port, default category, flag to control whether newlines are added to each line, and additional settings to be passed to ThriftClient.



8
9
10
11
12
13
# File 'lib/scribe/scribe.rb', line 8

def initialize(servers = "127.0.0.1:1463", category = "Ruby", add_newlines = true, options = {})
  @servers = servers
  @category = category
  @add_newlines = add_newlines
  @client = ThriftClient.new(ScribeThrift::Client, @servers, options.merge(PROTOCOL_OPTIONS))
end

Instance Method Details

#batchObject

Batch several calls to Scribe#log together. Yields to a block.



26
27
28
29
30
31
32
# File 'lib/scribe/scribe.rb', line 26

def batch
  @batch = []
  yield
  @client.Log(@batch)
ensure
  @batch = nil
end

#log(message, category = @category) ⇒ Object Also known as: debug, error, fatal, info, warn

Log a message. Accepts a string and an optional category.

Raises:

  • (ArgumentError)


16
17
18
19
20
21
22
23
# File 'lib/scribe/scribe.rb', line 16

def log(message, category = @category)
  raise ArgumentError, "Message must be a string" unless message.is_a?(String)
  raise ArgumentError, "Category must be a string" unless category.is_a?(String)

  message << "\n" if @add_newlines
  entry = ScribeThrift::LogEntry.new(:message => message, :category => category)
  @batch ? @batch << entry : @client.Log(Array(entry))
end