Class: CloudLogger::Loggly
Instance Method Summary collapse
-
#initialize(options) ⇒ Loggly
constructor
a json object with a data property which is an array with zero or more elements ResponseMatcher = /[s*({.*?)s]/m.
- #log(log_data) ⇒ Object
- #search(query) {|result| ... } ⇒ Object
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() @subdomain = [:subdomain] @user = [:user] @pass = [:pass] @key = [:key] @ec2 = [: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
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 |