cloud-logger 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ gem "rest-client", ">= 1.6.3"
7
+
8
+ # Add dependencies to develop your gem here.
9
+ # Include everything needed to run rake, tests, features, etc.
10
+ group :development do
11
+ gem "rspec", "> 2.3.0"
12
+ gem "bundler", "> 1.0.0"
13
+ gem "jeweler", ">= 1.6.4"
14
+ gem "rcov", ">= 0"
15
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Ryan Mitchell
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = cloud-logger
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to cloud-logger
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 Ryan Mitchell. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,50 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "cloud-logger"
18
+ gem.homepage = "http://github.com/ryan-mitchell/cloud-logger"
19
+ gem.license = "MIT"
20
+ gem.summary = "Simple Ruby interface to cloud logging services such as Loggly and Papertrail"
21
+ gem.description ="A simple Ruby interface to the APIs of various cloud logging services"
22
+ gem.email = "mitchellryanj@gmail.com"
23
+ gem.authors = ["Ryan Mitchell"]
24
+ gem.version = "0.0.1"
25
+ # dependencies defined in Gemfile
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rspec/core'
30
+ require 'rspec/core/rake_task'
31
+ RSpec::Core::RakeTask.new(:spec) do |spec|
32
+ spec.pattern = FileList['spec/**/*_spec.rb']
33
+ end
34
+
35
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
36
+ spec.pattern = 'spec/**/*_spec.rb'
37
+ spec.rcov = true
38
+ end
39
+
40
+ task :default => :spec
41
+
42
+ require 'rake/rdoctask'
43
+ Rake::RDocTask.new do |rdoc|
44
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
45
+
46
+ rdoc.rdoc_dir = 'rdoc'
47
+ rdoc.title = "cloud-logger #{version}"
48
+ rdoc.rdoc_files.include('README*')
49
+ rdoc.rdoc_files.include('lib/**/*.rb')
50
+ end
@@ -0,0 +1,66 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "cloud-logger"
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Ryan Mitchell"]
12
+ s.date = "2011-09-21"
13
+ s.description = "A simple Ruby interface to the APIs of various cloud logging services"
14
+ s.email = "mitchellryanj@gmail.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "cloud-logger.gemspec",
27
+ "lib/base.rb",
28
+ "lib/cloud-logger.rb",
29
+ "lib/event.rb",
30
+ "lib/loggly.rb",
31
+ "lib/papertrail.rb",
32
+ "spec/loggly_spec.rb",
33
+ "spec/papertrail_spec.rb",
34
+ "spec/spec_helper.rb"
35
+ ]
36
+ s.homepage = "http://github.com/ryan-mitchell/cloud-logger"
37
+ s.licenses = ["MIT"]
38
+ s.require_paths = ["lib"]
39
+ s.rubygems_version = "1.8.10"
40
+ s.summary = "Simple Ruby interface to cloud logging services such as Loggly and Papertrail"
41
+
42
+ if s.respond_to? :specification_version then
43
+ s.specification_version = 3
44
+
45
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
46
+ s.add_runtime_dependency(%q<rest-client>, [">= 1.6.3"])
47
+ s.add_development_dependency(%q<rspec>, ["> 2.3.0"])
48
+ s.add_development_dependency(%q<bundler>, ["> 1.0.0"])
49
+ s.add_development_dependency(%q<jeweler>, [">= 1.6.4"])
50
+ s.add_development_dependency(%q<rcov>, [">= 0"])
51
+ else
52
+ s.add_dependency(%q<rest-client>, [">= 1.6.3"])
53
+ s.add_dependency(%q<rspec>, ["> 2.3.0"])
54
+ s.add_dependency(%q<bundler>, ["> 1.0.0"])
55
+ s.add_dependency(%q<jeweler>, [">= 1.6.4"])
56
+ s.add_dependency(%q<rcov>, [">= 0"])
57
+ end
58
+ else
59
+ s.add_dependency(%q<rest-client>, [">= 1.6.3"])
60
+ s.add_dependency(%q<rspec>, ["> 2.3.0"])
61
+ s.add_dependency(%q<bundler>, ["> 1.0.0"])
62
+ s.add_dependency(%q<jeweler>, [">= 1.6.4"])
63
+ s.add_dependency(%q<rcov>, [">= 0"])
64
+ end
65
+ end
66
+
data/lib/base.rb ADDED
@@ -0,0 +1,5 @@
1
+ module CloudLogger
2
+
3
+ class Base
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'rest_client'
2
+ require 'base'
3
+ require 'event'
4
+ require 'loggly'
5
+ require 'papertrail'
data/lib/event.rb ADDED
@@ -0,0 +1,14 @@
1
+ require 'date'
2
+
3
+ module CloudLogger
4
+
5
+ class Event
6
+
7
+ attr_accessor :timestamp, :text
8
+
9
+ def initialize(text, timestamp)
10
+ @text = text
11
+ @timestamp = DateTime.parse(timestamp)
12
+ end
13
+ end
14
+ end
data/lib/loggly.rb ADDED
@@ -0,0 +1,30 @@
1
+ module CloudLogger
2
+
3
+ class Loggly
4
+
5
+ # a json object with a data property which is an array with zero or more elements
6
+ #ResponseMatcher = /\{\s*"data": \[\s*(\{.*?\})*\s*\]/m
7
+
8
+ def initialize(options)
9
+ @subdomain = options[:subdomain]
10
+ @user = options[:user]
11
+ @pass = options[:pass]
12
+ @key = options[:key]
13
+ @ec2 = options[:ec2] ||= false
14
+ end
15
+
16
+ def log(log_data)
17
+ ec2flag = @ec2 ? 'ec2.' : ''
18
+ RestClient.post("https://#{ec2flag}logs.loggly.com/inputs/#{@key}", log_data)
19
+ end
20
+
21
+ def search(query)
22
+ raw_response = RestClient.get("https://#{@user}:#{@pass}@#{@subdomain}.loggly.com/api/search", {:params => {:q => query}})
23
+ result = JSON.parse(raw_response)['data'].map do |log_entry|
24
+ CloudLogger::Event.new(log_entry['text'], log_entry['timestamp'])
25
+ end
26
+ yield result if block_given?
27
+ result
28
+ end
29
+ end
30
+ end
data/lib/papertrail.rb ADDED
@@ -0,0 +1,23 @@
1
+ module CloudLogger
2
+
3
+ class Papertrail
4
+
5
+ def initialize(options)
6
+ @user = options[:user]
7
+ @pass = options[:pass]
8
+ end
9
+
10
+ def log(message)
11
+ raise "sending logs is not supported for the Papertrail driver"
12
+ end
13
+
14
+ def search(query)
15
+ raw_response = RestClient.get("https://#{@user}:#{@pass}@papertrailapp.com/api/vi/events/search.json", {:params => {:q => query}})
16
+ result = JSON.parse(raw_response)['events'].map do |log_entry|
17
+ CloudLogger::Event.new(log_entry['message'], log_entry['received_at'])
18
+ end
19
+ yield result if block_given?
20
+ result
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,109 @@
1
+ require 'spec_helper'
2
+
3
+ describe CloudLogger::Loggly do
4
+
5
+ before(:all) do
6
+ @test_subdomain = 'example'
7
+ @test_user = 'user'
8
+ @test_pass = 'pass'
9
+ @test_key = '123456'
10
+ @loggly = CloudLogger::Loggly.new(
11
+ :subdomain => @test_subdomain,
12
+ :user => @test_user,
13
+ :pass => @test_pass,
14
+ :key => @test_key
15
+ )
16
+ end
17
+
18
+ describe "#search" do
19
+
20
+ before(:each) do
21
+ RestClient.stub!(:get)
22
+ Kernel.stub!(:print)
23
+ @test_response = JSON.generate({ :data => [ { :timestamp => "2011-09-21T18:48:55.151Z", :text => "Test Data" } ] })
24
+
25
+ end
26
+
27
+ it "should generate an appropriate RestClient GET" do
28
+
29
+ search_string = "search string"
30
+ RestClient.should_receive(:get).with(
31
+ "https://#{@test_user}:#{@test_pass}@#{@test_subdomain}.loggly.com/api/search",
32
+ {:params => {:q => search_string}}
33
+ ).and_return(@test_response)
34
+ @loggly.search(search_string)
35
+ end
36
+
37
+ it "should convert the returned text to a CloudLogger::Event" do
38
+ RestClient.should_receive(:get).and_return(@test_response)
39
+ @loggly.search("Test Data") do |data|
40
+ data.first.should be_instance_of CloudLogger::Event
41
+ data.first.text.should == "Test Data"
42
+ end
43
+ end
44
+
45
+ it "should execute the callback if one is provided" do
46
+
47
+ Kernel.should_receive(:print).with an_instance_of Array
48
+ RestClient.should_receive(:get).and_return(@test_response)
49
+
50
+ @loggly.search('anything') do |data|
51
+ Kernel.print data
52
+ data.first.should be_instance_of CloudLogger::Event
53
+ end
54
+ end
55
+
56
+ it "should return the response if no callback is provided" do
57
+
58
+ RestClient.should_receive(:get).and_return(@test_response)
59
+ @loggly.search('anything').should_not be_nil
60
+ end
61
+ end
62
+
63
+ describe "#log" do
64
+
65
+ before(:each) do
66
+ RestClient.stub!(:post)
67
+ end
68
+
69
+ it "should generate an appropriate RestClient POST with a raw payload" do
70
+
71
+ log_string = "this is a test log"
72
+ RestClient.should_receive(:post).with(
73
+ "https://logs.loggly.com/inputs/%s" % @test_key,
74
+ log_string
75
+ )
76
+
77
+ @loggly.log(log_string)
78
+ end
79
+
80
+ it "should generate an appropriate RestClient POST with parameters" do
81
+
82
+ log_parameters = { :time => 123456, :type => 'foo', :logger => 'bar' }
83
+ RestClient.should_receive(:post).with(
84
+ "https://logs.loggly.com/inputs/%s" % @test_key,
85
+ log_parameters
86
+ )
87
+
88
+ @loggly.log(log_parameters)
89
+ end
90
+
91
+ it "should use the EC2 host if the EC2 flag is set" do
92
+
93
+ log_string = "this is a test log"
94
+ ec2logger = CloudLogger::Loggly.new(
95
+ :subdomain => @test_subdomain,
96
+ :user => @test_user,
97
+ :pass => @test_pass,
98
+ :key => @test_key,
99
+ :ec2 => true
100
+ )
101
+ RestClient.should_receive(:post).with(
102
+ "https://ec2.logs.loggly.com/inputs/%s" % @test_key,
103
+ log_string
104
+ )
105
+
106
+ ec2logger.log(log_string)
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ describe CloudLogger::Papertrail do
4
+
5
+ before(:all) do
6
+ @test_user = 'user'
7
+ @test_pass = 'pass'
8
+ @logger = CloudLogger::Papertrail.new(
9
+ :user => @test_user,
10
+ :pass => @test_pass,
11
+ )
12
+ end
13
+
14
+ describe "#search" do
15
+
16
+ before(:each) do
17
+ RestClient.stub!(:get)
18
+ Kernel.stub!(:print)
19
+ @test_response = JSON.generate({ :events => [ { :received_at => "2011-09-21T18:48:55.15-07:00", :message => "Test Data" } ] })
20
+
21
+ end
22
+
23
+ it "should generate an appropriate RestClient GET" do
24
+
25
+ search_string = "search string"
26
+ RestClient.should_receive(:get).with(
27
+ "https://#{@test_user}:#{@test_pass}@papertrailapp.com/api/vi/events/search.json",
28
+ {:params => {:q => search_string}}
29
+ ).and_return(@test_response)
30
+ @logger.search(search_string)
31
+ end
32
+
33
+ it "should convert the returned text to a CloudLogger::Event" do
34
+ RestClient.should_receive(:get).and_return(@test_response)
35
+ @logger.search("Test Data") do |data|
36
+ data.first.should be_instance_of CloudLogger::Event
37
+ data.first.text.should == "Test Data"
38
+ end
39
+ end
40
+
41
+ it "should execute the callback if one is provided" do
42
+
43
+ Kernel.should_receive(:print).with an_instance_of Array
44
+ RestClient.should_receive(:get).and_return(@test_response)
45
+
46
+ @logger.search('anything') do |data|
47
+ Kernel.print data
48
+ data.first.should be_instance_of CloudLogger::Event
49
+ end
50
+ end
51
+
52
+ it "should return the response if no callback is provided" do
53
+
54
+ RestClient.should_receive(:get).and_return(@test_response)
55
+ @logger.search('anything').should_not be_nil
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,13 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'cloud-logger'
5
+ require 'json'
6
+
7
+ # Requires supporting files with custom matchers and macros, etc,
8
+ # in ./support/ and its subdirectories.
9
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
10
+
11
+ RSpec.configure do |config|
12
+
13
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cloud-logger
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ryan Mitchell
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-09-21 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rest-client
16
+ requirement: &25526720 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.6.3
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *25526720
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &25526240 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>'
31
+ - !ruby/object:Gem::Version
32
+ version: 2.3.0
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *25526240
36
+ - !ruby/object:Gem::Dependency
37
+ name: bundler
38
+ requirement: &25525640 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>'
42
+ - !ruby/object:Gem::Version
43
+ version: 1.0.0
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *25525640
47
+ - !ruby/object:Gem::Dependency
48
+ name: jeweler
49
+ requirement: &25525140 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 1.6.4
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *25525140
58
+ - !ruby/object:Gem::Dependency
59
+ name: rcov
60
+ requirement: &25524620 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *25524620
69
+ description: A simple Ruby interface to the APIs of various cloud logging services
70
+ email: mitchellryanj@gmail.com
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files:
74
+ - LICENSE.txt
75
+ - README.rdoc
76
+ files:
77
+ - .document
78
+ - .rspec
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.rdoc
82
+ - Rakefile
83
+ - cloud-logger.gemspec
84
+ - lib/base.rb
85
+ - lib/cloud-logger.rb
86
+ - lib/event.rb
87
+ - lib/loggly.rb
88
+ - lib/papertrail.rb
89
+ - spec/loggly_spec.rb
90
+ - spec/papertrail_spec.rb
91
+ - spec/spec_helper.rb
92
+ homepage: http://github.com/ryan-mitchell/cloud-logger
93
+ licenses:
94
+ - MIT
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ segments:
106
+ - 0
107
+ hash: 196934442856709586
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ! '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 1.8.10
117
+ signing_key:
118
+ specification_version: 3
119
+ summary: Simple Ruby interface to cloud logging services such as Loggly and Papertrail
120
+ test_files: []