logger-http 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +34 -0
- data/Rakefile +1 -0
- data/lib/logger-http.rb +11 -0
- data/lib/logger-http/base.rb +70 -0
- data/lib/logger-http/delegator.rb +10 -0
- data/lib/logger-http/put.rb +10 -0
- data/lib/logger-http/version.rb +3 -0
- data/logger-http.gemspec +27 -0
- data/spec/logger-spec.rb +9 -0
- data/spec/spec_helper.rb +8 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4a242d1de8bedbe5215bbd10280989241dc4e404
|
4
|
+
data.tar.gz: 09964a3b79e7180c5cbb5dcbfb5895610b9201c0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 98c7e6c4bd3b852748ca4798aacf95ca749a1b6ea5b7e2652cb214e05a74ebcb949ca609680161cb2dd5a065b58ce945bc4bd9da45b987ea18c8b77984826d08
|
7
|
+
data.tar.gz: b3beb6a8e68c8e9ebebb299854313f5be98b3b98620e4adc535f2f01cde737091661a93041204184981cd8ed9a5cfbd3e1f242b7ad15626b0738850e58f39119
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Frans Krojegård
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# Logger::HTTP
|
2
|
+
|
3
|
+
A Ruby logger over HTTP. Uses PUT for logging, for now at least.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'logger-http'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install logger-http
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
config.logger = Logger::HTTP.new('https://data.logentries.com', '/ACCOUNT_KEY/hosts/HOST/LOG/?realtime=1')
|
22
|
+
|
23
|
+
## TODO
|
24
|
+
|
25
|
+
- Buffer requests
|
26
|
+
- More methods than PUT?
|
27
|
+
|
28
|
+
## Contributing
|
29
|
+
|
30
|
+
1. Fork it
|
31
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
32
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
33
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
34
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/logger-http.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require "logger-http/version"
|
2
|
+
require 'logger-http/put'
|
3
|
+
require 'logger-http/base'
|
4
|
+
|
5
|
+
require 'logger'
|
6
|
+
|
7
|
+
module Logger::HTTP
|
8
|
+
def self.new(base_uri, path, debug: false)
|
9
|
+
Logger.new(::Logger::HTTP::Base.new(base_uri, path, Logger::HTTP::Put, debug: debug))
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
class Logger::HTTP::Base
|
2
|
+
def initialize(base_uri, path, request_source, debug: false)
|
3
|
+
@base_uri = URI.parse(base_uri)
|
4
|
+
@path = path
|
5
|
+
@debug_logger = Logger.new('log/logger-http.log') if debug
|
6
|
+
@request_source = request_source
|
7
|
+
@queue = Queue.new
|
8
|
+
dbg "initialized"
|
9
|
+
end
|
10
|
+
|
11
|
+
def write(message)
|
12
|
+
dbg "queueing message"
|
13
|
+
start
|
14
|
+
|
15
|
+
@queue << "#{message}\n"
|
16
|
+
rescue StandardError => e
|
17
|
+
dbg "#{self.class} - #{e.class} - #{e.message}"
|
18
|
+
close
|
19
|
+
end
|
20
|
+
|
21
|
+
def start
|
22
|
+
@thread ||= Thread.new { run }
|
23
|
+
@thread = Thread.new { run } unless @thread.alive?
|
24
|
+
dbg "thread is #{@thread.status}"
|
25
|
+
end
|
26
|
+
|
27
|
+
def dbg message
|
28
|
+
@debug_logger && @debug_logger.debug(message)
|
29
|
+
end
|
30
|
+
|
31
|
+
def run
|
32
|
+
dbg "running loop"
|
33
|
+
|
34
|
+
loop do
|
35
|
+
data = @queue.pop
|
36
|
+
dbg "popped #{data}"
|
37
|
+
|
38
|
+
unless data
|
39
|
+
dbg "no data!"
|
40
|
+
sleep 3
|
41
|
+
next
|
42
|
+
end
|
43
|
+
|
44
|
+
dbg "Sending message"
|
45
|
+
request(data)
|
46
|
+
end
|
47
|
+
|
48
|
+
rescue StandardError
|
49
|
+
dbg("Got exception in run loop - #{ $! }")
|
50
|
+
@connection = nil
|
51
|
+
raise
|
52
|
+
end
|
53
|
+
|
54
|
+
def close
|
55
|
+
stop
|
56
|
+
connection && connection.finish
|
57
|
+
rescue StandardError => e
|
58
|
+
dbg "#{self.class} - #{e.class} - #{e.message}"
|
59
|
+
end
|
60
|
+
|
61
|
+
def request data
|
62
|
+
put = @request_source.new(@path, data)
|
63
|
+
connection.request @base_uri + @path, put
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
def connection
|
68
|
+
@connection ||= Net::HTTP::Persistent.new('logger')
|
69
|
+
end
|
70
|
+
end
|
data/logger-http.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'logger'
|
5
|
+
require 'logger-http/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "logger-http"
|
9
|
+
spec.version = Logger::HTTP::VERSION
|
10
|
+
spec.authors = ["Frans Krojegård"]
|
11
|
+
spec.email = ["frans@krojegard.com"]
|
12
|
+
spec.description = "A http logger"
|
13
|
+
spec.summary = "A Ruby logger over HTTP"
|
14
|
+
spec.homepage = ""
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files`.split($/)
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency 'net-http-persistent'
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency "minitest"
|
27
|
+
end
|
data/spec/logger-spec.rb
ADDED
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: logger-http
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Frans Krojegård
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: net-http-persistent
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: A http logger
|
70
|
+
email:
|
71
|
+
- frans@krojegard.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- lib/logger-http.rb
|
82
|
+
- lib/logger-http/base.rb
|
83
|
+
- lib/logger-http/delegator.rb
|
84
|
+
- lib/logger-http/put.rb
|
85
|
+
- lib/logger-http/version.rb
|
86
|
+
- logger-http.gemspec
|
87
|
+
- spec/logger-spec.rb
|
88
|
+
- spec/spec_helper.rb
|
89
|
+
homepage: ''
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata: {}
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.1.4
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: A Ruby logger over HTTP
|
113
|
+
test_files:
|
114
|
+
- spec/logger-spec.rb
|
115
|
+
- spec/spec_helper.rb
|