logglier 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -0
- data/README.md +25 -0
- data/Rakefile +10 -0
- data/lib/logglier/client.rb +47 -0
- data/lib/logglier/version.rb +3 -0
- data/lib/logglier.rb +11 -0
- data/logglier.gemspec +27 -0
- data/spec/client_spec.rb +53 -0
- data/spec/logglier_spec.rb +6 -0
- data/spec/spec_helper.rb +12 -0
- metadata +109 -0
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
Overview
|
2
|
+
--------
|
3
|
+
|
4
|
+
Posts Logger messages to Loggly using the HTTP API.
|
5
|
+
|
6
|
+
|
7
|
+
Usage
|
8
|
+
-----
|
9
|
+
|
10
|
+
require 'logger'
|
11
|
+
require 'logglier'
|
12
|
+
|
13
|
+
log = Logger.new(Logglier.new(<INPUT URL>))
|
14
|
+
|
15
|
+
log.info("hello from logglier")
|
16
|
+
|
17
|
+
|
18
|
+
TODO
|
19
|
+
-----
|
20
|
+
|
21
|
+
* Alternative https implementations (Typheous, Excon, etc). May be
|
22
|
+
faster?
|
23
|
+
* Option to use Syslog (via UDP and/or TCP) inputs. Possibly faster than
|
24
|
+
the https inputs.
|
25
|
+
* Do logging in a seperate thread. Is this useful? Too complex?
|
data/Rakefile
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'net/https'
|
2
|
+
require 'uri'
|
3
|
+
|
4
|
+
module Logglier
|
5
|
+
class Client
|
6
|
+
|
7
|
+
attr_reader :input_uri, :http
|
8
|
+
|
9
|
+
def initialize(opts={})
|
10
|
+
opts = { :input_url => opts } if opts.is_a?(String)
|
11
|
+
@input_uri = opts[:input_url]
|
12
|
+
|
13
|
+
if opts.nil? or opts.empty?
|
14
|
+
raise InputURLRequired.new
|
15
|
+
end
|
16
|
+
|
17
|
+
begin
|
18
|
+
@input_uri = URI.parse(@input_uri)
|
19
|
+
rescue URI::InvalidURIError => e
|
20
|
+
raise InputURLRequired.new("Invalid Input URL: #{@input_uri}")
|
21
|
+
end
|
22
|
+
|
23
|
+
@http = Net::HTTP.new(@input_uri.host, @input_uri.port)
|
24
|
+
if @input_uri.scheme == 'https'
|
25
|
+
@http.use_ssl = true
|
26
|
+
@http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
27
|
+
end
|
28
|
+
|
29
|
+
@http.read_timeout = opts[:read_timeout] || 2
|
30
|
+
@http.open_timeout = opts[:open_timeout] || 2
|
31
|
+
end
|
32
|
+
|
33
|
+
# Required by Logger::LogDevice
|
34
|
+
def write(message)
|
35
|
+
begin
|
36
|
+
@http.start { @http.request_post(@input_uri.path, message) }
|
37
|
+
rescue TimeoutError => e
|
38
|
+
$stderr.puts "WARNING: TimeoutError posting message: #{message}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Required by Logger::LogDevice
|
43
|
+
def close
|
44
|
+
nil
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/logglier.rb
ADDED
data/logglier.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
dir = File.dirname(__FILE__)
|
2
|
+
require File.expand_path(File.join(dir, 'lib', 'logglier', 'version'))
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "logglier"
|
6
|
+
s.version = Logglier::VERSION
|
7
|
+
s.date = '2011-02-25'
|
8
|
+
s.summary = "Loggly 'plugin' for Logger"
|
9
|
+
s.description =<<EOD
|
10
|
+
Logger => Loggly
|
11
|
+
EOD
|
12
|
+
|
13
|
+
s.authors = ["Edward Muller (aka freeformz)"]
|
14
|
+
s.email =
|
15
|
+
s.homepage = "http://loggly.com"
|
16
|
+
|
17
|
+
s.files = %w{ README.md Gemfile logglier.gemspec Rakefile } + Dir["#{dir}/lib/**/*.rb"]
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
s.test_files = Dir["#{dir}/spec/**/*.rb"]
|
20
|
+
|
21
|
+
s.rubyforge_project = "logglier"
|
22
|
+
|
23
|
+
s.add_development_dependency 'rake'
|
24
|
+
s.add_development_dependency 'rspec', '~> 2.5.0'
|
25
|
+
end
|
26
|
+
|
27
|
+
|
data/spec/client_spec.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Logglier::Client do
|
4
|
+
|
5
|
+
context "#new" do
|
6
|
+
|
7
|
+
context "w/o any params" do
|
8
|
+
|
9
|
+
it "should raise an error" do
|
10
|
+
expect { Logglier::Client.new() }.to raise_error Logglier::InputURLRequired
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
context "a single string param" do
|
16
|
+
|
17
|
+
context "that is a valid uri" do
|
18
|
+
|
19
|
+
it "should return and instance of itself" do
|
20
|
+
log = Logglier::Client.new('http://localhost')
|
21
|
+
log.should be_an_instance_of Logglier::Client
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
context "that is NOT a valid uri" do
|
27
|
+
|
28
|
+
it "should raise an error" do
|
29
|
+
expect { Logglier::Client.new('f://://://') }.to raise_error Logglier::InputURLRequired
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
context "#write" do
|
39
|
+
before do
|
40
|
+
@log = Logglier::Client.new('https://localhost')
|
41
|
+
@log.http.stub(:start)
|
42
|
+
end
|
43
|
+
|
44
|
+
context "with a message" do
|
45
|
+
|
46
|
+
it "should start a http call" do
|
47
|
+
@log.http.should_receive(:start)
|
48
|
+
@log.write('msg')
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: logglier
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Edward Muller (aka freeformz)
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-02-25 00:00:00 -08:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rake
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rspec
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 27
|
44
|
+
segments:
|
45
|
+
- 2
|
46
|
+
- 5
|
47
|
+
- 0
|
48
|
+
version: 2.5.0
|
49
|
+
type: :development
|
50
|
+
version_requirements: *id002
|
51
|
+
description: |
|
52
|
+
Logger => Loggly
|
53
|
+
|
54
|
+
email: http://loggly.com
|
55
|
+
executables: []
|
56
|
+
|
57
|
+
extensions: []
|
58
|
+
|
59
|
+
extra_rdoc_files: []
|
60
|
+
|
61
|
+
files:
|
62
|
+
- README.md
|
63
|
+
- Gemfile
|
64
|
+
- logglier.gemspec
|
65
|
+
- Rakefile
|
66
|
+
- ./lib/logglier.rb
|
67
|
+
- ./lib/logglier/client.rb
|
68
|
+
- ./lib/logglier/version.rb
|
69
|
+
- ./spec/client_spec.rb
|
70
|
+
- ./spec/logglier_spec.rb
|
71
|
+
- ./spec/spec_helper.rb
|
72
|
+
has_rdoc: true
|
73
|
+
homepage: http://loggly.com
|
74
|
+
licenses: []
|
75
|
+
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
hash: 3
|
87
|
+
segments:
|
88
|
+
- 0
|
89
|
+
version: "0"
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
hash: 3
|
96
|
+
segments:
|
97
|
+
- 0
|
98
|
+
version: "0"
|
99
|
+
requirements: []
|
100
|
+
|
101
|
+
rubyforge_project: logglier
|
102
|
+
rubygems_version: 1.3.7
|
103
|
+
signing_key:
|
104
|
+
specification_version: 3
|
105
|
+
summary: Loggly 'plugin' for Logger
|
106
|
+
test_files:
|
107
|
+
- ./spec/client_spec.rb
|
108
|
+
- ./spec/logglier_spec.rb
|
109
|
+
- ./spec/spec_helper.rb
|