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



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

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



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

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

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

Yields:

  • (result)


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

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