Class: CloudLogger::Loggly

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

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Loggly

a json object with a data property which is an array with zero or more elements ResponseMatcher = /[s*({.*?)s]/m



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

def initialize(options)
  @subdomain = options[:subdomain]
  @user = options[:user]
  @pass = options[:pass]
  @key = options[:key]
  @ec2 = options[:ec2] ||= false
end

Instance Method Details

#log(log_data) ⇒ Object



16
17
18
19
# File 'lib/loggly.rb', line 16

def log(log_data)
  ec2flag = @ec2 ? 'ec2.' : ''
  RestClient.post("https://#{ec2flag}logs.loggly.com/inputs/#{@key}", log_data)
end

#search(query) {|result| ... } ⇒ Object

Yields:

  • (result)


21
22
23
24
25
26
27
28
# File 'lib/loggly.rb', line 21

def search(query)
  raw_response = RestClient.get("https://#{@user}:#{@pass}@#{@subdomain}.loggly.com/api/search", {:params => {:q => query}})
  result = JSON.parse(raw_response)['data'].map do |log_entry|
    CloudLogger::Event.new(log_entry['text'], log_entry['timestamp'])
  end 
  yield result if block_given?
  result
end