le 2.2.9 → 2.3.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 84d1ea5039bc8264fe26850b807253c23ac5a5f6
4
- data.tar.gz: 768cc4836bdad93ca95270424949ab1b7ebe477a
3
+ metadata.gz: 197d934adfa495609d70c30c00d450a363a5fd8f
4
+ data.tar.gz: 14719f1f0549fa73898046babe65c80937f9b2e5
5
5
  SHA512:
6
- metadata.gz: 9189e9168f16f77db1cc7883f5a52b5d6c62fcfef32fef403f74f62a652a0ee2a3ce2070c9bd9f0a595e87d697407d57cfaec22e4bb3ef51f66f3cca71d9de4e
7
- data.tar.gz: 4876d219250d9e171d2b6dfc9fd61665c099cda60edb1cbe38f11b30388ffec9a93377563928a7e17850cf3fa0d4b23693dafc2089025a1c63f318f480d3ddd8
6
+ metadata.gz: 6c7d3c26d04a8cf0dd8e9181a307c63bfccebe1ed7e47fe6cf4831df2e0b590133ba37293794f431dbdc5d160368c68e54cedd8db85fd9105f1a6fcee22866fc
7
+ data.tar.gz: 0716d1ba6ab62a8a0a39dde7c31cc8b6bfabcaa2e463d6e152e07ca1c35df6d3ea12495d3d635fa0d6264e52e7c15aef273a40ab79b66bbb6edf20ced263d178
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .rvmrc
19
+ .ruby-*
20
+ *.log
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LE.gemspec CHANGED
@@ -1,20 +1,28 @@
1
- dir = File.dirname(__FILE__)
2
- require File.expand_path(File.join(dir, 'lib', 'le'))
3
-
4
- Gem::Specification.new do |s|
5
- s.name = "le"
6
- s.version = "2.2.9"
7
- s.date = Time.now
8
- s.summary = "Logentries plugin"
9
- s.licenses = ["MIT"]
10
- s.description =<<EOD
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'le'
11
5
 
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "le"
8
+ gem.version = "2.3.9"
9
+ gem.date = Time.now
10
+ gem.summary = "Logentries plugin"
11
+ gem.licenses = ["MIT"]
12
+ gem.description =<<EOD
12
13
 
13
14
  EOD
14
15
 
15
- s.authors = ["Mark Lacomber"]
16
- s.email = "mark.lacomber@logentries.com"
17
- s.homepage = "https://github.com/logentries/le_ruby"
18
- s.files = %w{ LE.gemspec } + Dir["#{dir}/lib/**/*.rb"]
19
- s.require_paths = ["lib"]
16
+ gem.authors = ["Mark Lacomber"]
17
+ gem.email = "mark.lacomber@logentries.com"
18
+ gem.homepage = "https://github.com/logentries/le_ruby"
19
+ gem.files = `git ls-files`.split($/)
20
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
21
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
22
+ gem.require_paths = ["lib"]
23
+
24
+ gem.add_development_dependency "bundler"
25
+ gem.add_development_dependency "rake"
26
+ gem.add_development_dependency 'minitest'
27
+
20
28
  end
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2014 Logentries
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,75 @@
1
+ Logging to Logentries in Ruby
2
+ =============================
3
+
4
+ This is a Logentries library for logging from Ruby platforms, including Heroku.
5
+
6
+ It is available on github <https://github.com/logentries/le_ruby/> and rubygems
7
+ <http://rubygems.org/>.
8
+
9
+
10
+ Example
11
+ -------
12
+
13
+ Rails.logger.info("information message")
14
+ Rails.logger.warn("warning message")
15
+ Rails.logger.debug("debug message")
16
+
17
+
18
+ Howto
19
+ -----
20
+
21
+ You must first register your account details with Logentries.
22
+
23
+ Once you have logged in to Logentries, create a new host with a name of your choice.
24
+ Inside this host, create a new logfile, selecting `Token TCP` as the source type.
25
+
26
+ Heroku
27
+ ------
28
+
29
+ To install the gem you must edit the Gemfile in your local heroku environment
30
+
31
+ Add the following line:
32
+
33
+ gem 'le'
34
+
35
+ Then from the cmd line run the following command:
36
+
37
+ bundle install
38
+
39
+ This will install the gem on your local environment.
40
+
41
+ The next step is to configure the default rails logger to use the logentries
42
+ logger.
43
+
44
+ In your environment configuration file ( for production : `config/environments/production.rb`), add the following:
45
+
46
+ Rails.logger = Le.new('LOGENTRIES_TOKEN')
47
+
48
+ If you want to keep logging locally in addition to sending logs to logentries, just add local parameter after the key.
49
+ By default, this will write to the standard Rails log or to STDOUT if not using Rails:
50
+
51
+ Rails.logger = Le.new('LOGENTRIES_TOKEN', :local => true)
52
+
53
+ You may specify the local log device by providing a filename (String) or IO object (typically STDOUT, STDERR, or an open file):
54
+
55
+ Rails.logger = Le.new('LOGENTRIES_TOKEN', :local => 'log/my_custom_log.log')
56
+
57
+ If you want the gem to use SSL when streaming logs to Logentries, add the ssl parameter and set it to true:
58
+
59
+ Rails.logger = Le.new('LOGENTRIES_TOKEN', :ssl => true)
60
+
61
+ If you want to print debug messages for the gem to a file called logentriesGem.log, add this:
62
+
63
+ Rails.logger = Le.new('LOGENTRIES_TOKEN', :debug => true)
64
+
65
+ If you want to use ActiveSupport::TaggedLogging logging, add this:
66
+
67
+ Rails.logger = Le.new('LOGENTRIES_TOKEN', :tag => true)
68
+
69
+ You can also specify the default level of the logger by adding a :
70
+
71
+ Rails.logger = Le.new('LOGENTRIES_TOKEN', :log_level => Logger::<level>)
72
+
73
+ For the `LOGENTRIES_TOKEN` argument, paste the token for the logfile you created earlier in the Logentries UI.
74
+
75
+ Now, simply use `Rails.logger.info("message")` inside your code to send logs to Logentries
@@ -0,0 +1,16 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs = ['lib','test']
6
+ t.test_files = Dir.glob("test/**/*_spec.rb").sort
7
+ t.verbose = true
8
+ end
9
+
10
+ task :default => [:test]
11
+ task :spec => [:test]
12
+
13
+ desc "Open an irb session preloaded with this library"
14
+ task :console do
15
+ sh "irb -rubygems -I lib -r le.rb"
16
+ end
@@ -41,6 +41,9 @@ wVYQgpYWRRZ7bJyfRCJxzIdYF3qy/P9NWyZSlDUuv11s1GSFO2pNd34p59GacVAL
41
41
  BJE6y5eOPTSbtkmBW/ukaVYdI5NLXNer3IaK3fetV3LvYGOaX8hR45FI1pvyKYvf
42
42
  S5ol3bQmY1mv78XKkOk=
43
43
  -----END CERTIFICATE-----'
44
+ SHUTDOWN_COMMAND = "DIE!DIE!" # magic command string for async worker to shutdown
45
+ SHUTDOWN_MAX_WAIT = 10 # max seconds to wait for queue to clear on shutdown
46
+ SHUTDOWN_WAIT_STEP = 0.2 # sleep duration (seconds) while waiting to shutdown
44
47
 
45
48
 
46
49
  include Le::Host::InstanceMethods
@@ -48,14 +51,19 @@ S5ol3bQmY1mv78XKkOk=
48
51
 
49
52
  def initialize(token, local, debug, ssl)
50
53
  if local
51
- if defined?(Rails)
52
- @logger_console = Logger.new("log/#{Rails.env}.log")
54
+ device = if local.class <= TrueClass
55
+ if defined?(Rails)
56
+ Rails.root.join("log","#{Rails.env}.log")
57
+ else
58
+ STDOUT
59
+ end
53
60
  else
54
- @logger_console = Logger.new(STDOUT)
61
+ local
55
62
  end
63
+ @logger_console = Logger.new(device)
56
64
  end
57
65
  @token = token
58
- @local = local
66
+ @local = !!local
59
67
  @debug = debug
60
68
  @ssl = ssl
61
69
  @queue = Queue.new
@@ -67,6 +75,7 @@ S5ol3bQmY1mv78XKkOk=
67
75
  if @debug
68
76
  self.init_debug
69
77
  end
78
+ at_exit { shutdown! }
70
79
  end
71
80
 
72
81
  def init_debug
@@ -178,6 +187,7 @@ S5ol3bQmY1mv78XKkOk=
178
187
 
179
188
  loop do
180
189
  data = @queue.pop
190
+ break if data == SHUTDOWN_COMMAND
181
191
  loop do
182
192
  begin
183
193
  @conn.write(data)
@@ -204,6 +214,20 @@ S5ol3bQmY1mv78XKkOk=
204
214
  @random_message_id_sample_space ||= ('0'..'9').to_a.concat(('A'..'Z').to_a)
205
215
  (0..5).map{ @random_message_id_sample_space.sample }.join
206
216
  end
217
+
218
+ # at_exit handler.
219
+ # Attempts to clear the queue and terminate the async worker cleanly before process ends.
220
+ def shutdown!
221
+ return unless @started
222
+ dbg "LE: commencing shutdown, queue has #{queue.size} entries to clear"
223
+ queue << SHUTDOWN_COMMAND
224
+ SHUTDOWN_MAX_WAIT.div(SHUTDOWN_WAIT_STEP).times do
225
+ break if queue.empty?
226
+ sleep SHUTDOWN_WAIT_STEP
227
+ end
228
+ dbg "LE: shutdown complete, queue is #{queue.empty? ? '' : 'not '}empty with #{queue.size} entries"
229
+ end
230
+
207
231
  end
208
232
  end
209
233
  end
@@ -0,0 +1 @@
1
+ *.log
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Le::Host do
4
+
5
+ let(:token) { '11111111-2222-3333-aaaa-bbbbbbbbbbbb' }
6
+ let(:local) { false }
7
+ let(:debug) { false }
8
+ let(:ssl) { false }
9
+ let(:host) { Le::Host.new(token, local, debug, ssl) }
10
+
11
+ specify { host.must_be_instance_of Le::Host::HTTP }
12
+
13
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+ require 'pathname'
3
+
4
+ describe Le::Host::HTTP do
5
+
6
+ let(:token) { '11111111-2222-3333-aaaa-bbbbbbbbbbbb' }
7
+ let(:local) { false }
8
+ let(:debug) { false }
9
+ let(:ssl) { false }
10
+ let(:host) { Le::Host::HTTP.new(token, local, debug, ssl) }
11
+ let(:logger_console) { host.instance_variable_get(:@logger_console) }
12
+ let(:logger_console_dev) { logger_console.instance_variable_get(:@logdev).dev }
13
+
14
+ specify { host.must_be_instance_of Le::Host::HTTP }
15
+ specify { host.local.must_equal false }
16
+ specify { host.debug.must_equal false }
17
+ specify { host.ssl.must_equal false }
18
+
19
+ end
@@ -0,0 +1,142 @@
1
+ require 'spec_helper'
2
+
3
+ describe Le do
4
+
5
+ let(:token) { '11111111-2222-3333-aaaa-bbbbbbbbbbbb' }
6
+ let(:local) { false }
7
+ let(:logger) { Le.new(token, local: local) }
8
+ let(:logdev) { logger.instance_variable_get(:@logdev).dev }
9
+ let(:logger_console) { logdev.instance_variable_get(:@logger_console) }
10
+ let(:logger_console_dev) { logger_console.instance_variable_get(:@logdev).dev }
11
+
12
+
13
+ describe "when non-Rails environment" do
14
+
15
+ describe "when initialised with just a token" do
16
+ let(:logger) { Le.new(token) }
17
+ specify { logger.must_be_instance_of Logger }
18
+ specify { logdev.must_be_instance_of Le::Host::HTTP }
19
+ specify { logdev.local.must_equal false }
20
+ specify { logger_console.must_be_nil }
21
+ end
22
+
23
+ describe "and :local is false" do
24
+ specify { logdev.local.must_equal false }
25
+ specify { logger_console.must_be_nil }
26
+ end
27
+
28
+ describe "and :local is true" do
29
+ let(:local) { true }
30
+
31
+ specify { logdev.local.must_equal true }
32
+ specify { logger_console.must_be_instance_of Logger }
33
+ specify { logger_console_dev.must_be_instance_of IO }
34
+ end
35
+
36
+
37
+ describe "and :local => " do
38
+ let(:local_test_log) { Pathname.new(File.dirname(__FILE__)).join('fixtures','log','local_log.log') }
39
+ let(:local) { log_file }
40
+
41
+ describe "Pathname" do
42
+ let(:log_file) { local_test_log }
43
+
44
+ specify { logdev.must_be_instance_of Le::Host::HTTP }
45
+ specify { logdev.local.must_equal true }
46
+ specify { logger_console.must_be_instance_of Logger }
47
+ specify { logger_console_dev.must_be_instance_of File }
48
+ specify { logger_console_dev.path.must_match 'local_log.log' }
49
+ end
50
+
51
+ describe "path string" do
52
+ let(:log_file) { local_test_log.to_s }
53
+
54
+ specify { logdev.must_be_instance_of Le::Host::HTTP }
55
+ specify { logdev.local.must_equal true }
56
+ specify { logger_console.must_be_instance_of Logger }
57
+ specify { logger_console_dev.must_be_instance_of File }
58
+ specify { logger_console_dev.path.must_match 'local_log.log' }
59
+ end
60
+
61
+ describe "File" do
62
+ let(:log_file) { File.new(local_test_log) }
63
+
64
+ specify { logdev.must_be_instance_of Le::Host::HTTP }
65
+ specify { logdev.local.must_equal true }
66
+ specify { logger_console.must_be_instance_of Logger }
67
+ specify { logger_console_dev.must_be_instance_of File }
68
+ specify { logger_console_dev.path.must_match 'local_log.log' }
69
+ end
70
+
71
+ end
72
+
73
+ end
74
+
75
+ describe "when Rails environment" do
76
+ before do
77
+ class Rails
78
+ def self.root
79
+ Pathname.new(File.dirname(__FILE__)).join('fixtures')
80
+ end
81
+ def self.env
82
+ 'test'
83
+ end
84
+ end
85
+ end
86
+ after do
87
+ Object.send(:remove_const, :Rails)
88
+ end
89
+
90
+ describe "and :local is false" do
91
+ specify { logdev.local.must_equal false }
92
+ specify { logger_console.must_be_nil }
93
+ end
94
+
95
+ describe "and :local is true" do
96
+ let(:local) { true }
97
+
98
+ specify { logdev.local.must_equal true }
99
+ specify { logger_console.must_be_instance_of Logger }
100
+ specify { logger_console_dev.must_be_instance_of File }
101
+ specify { logger_console_dev.path.must_match 'test.log' }
102
+ end
103
+
104
+ describe "and :local => " do
105
+ let(:local_test_log) { Pathname.new(File.dirname(__FILE__)).join('fixtures','log','local_log.log') }
106
+ let(:local) { log_file }
107
+
108
+ describe "Pathname" do
109
+ let(:log_file) { local_test_log }
110
+
111
+ specify { logdev.must_be_instance_of Le::Host::HTTP }
112
+ specify { logdev.local.must_equal true }
113
+ specify { logger_console.must_be_instance_of Logger }
114
+ specify { logger_console_dev.must_be_instance_of File }
115
+ specify { logger_console_dev.path.must_match 'local_log.log' }
116
+ end
117
+
118
+ describe "path string" do
119
+ let(:log_file) { local_test_log.to_s }
120
+
121
+ specify { logdev.must_be_instance_of Le::Host::HTTP }
122
+ specify { logdev.local.must_equal true }
123
+ specify { logger_console.must_be_instance_of Logger }
124
+ specify { logger_console_dev.must_be_instance_of File }
125
+ specify { logger_console_dev.path.must_match 'local_log.log' }
126
+ end
127
+
128
+ describe "File" do
129
+ let(:log_file) { File.new(local_test_log) }
130
+
131
+ specify { logdev.must_be_instance_of Le::Host::HTTP }
132
+ specify { logdev.local.must_equal true }
133
+ specify { logger_console.must_be_instance_of Logger }
134
+ specify { logger_console_dev.must_be_instance_of File }
135
+ specify { logger_console_dev.path.must_match 'local_log.log' }
136
+ end
137
+
138
+ end
139
+
140
+ end
141
+
142
+ end
@@ -0,0 +1,2 @@
1
+ require 'minitest/autorun'
2
+ require 'le'
metadata CHANGED
@@ -1,27 +1,78 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: le
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.9
4
+ version: 2.3.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Lacomber
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-30 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2014-06-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
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: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
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'
13
55
  description: |2+
14
56
 
15
-
16
57
  email: mark.lacomber@logentries.com
17
58
  executables: []
18
59
  extensions: []
19
60
  extra_rdoc_files: []
20
61
  files:
62
+ - .gitignore
63
+ - Gemfile
21
64
  - LE.gemspec
22
- - ./lib/le/host.rb
23
- - ./lib/le/host/http.rb
24
- - ./lib/le.rb
65
+ - LICENSE
66
+ - README.md
67
+ - Rakefile
68
+ - lib/le.rb
69
+ - lib/le/host.rb
70
+ - lib/le/host/http.rb
71
+ - test/fixtures/log/.gitignore
72
+ - test/host_spec.rb
73
+ - test/http_spec.rb
74
+ - test/le_spec.rb
75
+ - test/spec_helper.rb
25
76
  homepage: https://github.com/logentries/le_ruby
26
77
  licenses:
27
78
  - MIT
@@ -42,8 +93,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
42
93
  version: '0'
43
94
  requirements: []
44
95
  rubyforge_project:
45
- rubygems_version: 2.1.8
96
+ rubygems_version: 2.2.2
46
97
  signing_key:
47
98
  specification_version: 4
48
99
  summary: Logentries plugin
49
- test_files: []
100
+ test_files:
101
+ - test/fixtures/log/.gitignore
102
+ - test/host_spec.rb
103
+ - test/http_spec.rb
104
+ - test/le_spec.rb
105
+ - test/spec_helper.rb