Sha256: 24feb17035e65bd2b6effa45dfbdc6ab33a8f33b9f687b330ab3be297cbb7bcb

Contents?: true

Size: 848 Bytes

Versions: 1

Compression:

Stored size: 848 Bytes

Contents

class Scribe
  def initialize(host = "127.0.0.1", port = 1463, category = "Ruby")
    @host = host
    @port = port
    @category = category

    transport = Thrift::FramedTransport.new(Thrift::Socket.new(@host, @port))
    transport.open
    
    @client = ScribeThrift::SafeClient.new(
      ScribeThrift::Client.new(Thrift::BinaryProtocol.new(transport, false)),
      transport)
  end

  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)
    
    entry = ScribeThrift::LogEntry.new(:message => message, :category => category)
    @batch ? @batch << entry : @client.Log(Array(entry))
  end
  
  def batch
    @batch = []
    yield
    @client.Log(@batch)
  ensure
    @batch = nil
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
scribe-0.1 lib/scribe/scribe.rb