le 2.5.0 → 2.6.0

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: 8106a0e740c344c588e5bfb06acb2d55af4d5437
4
- data.tar.gz: 2b9b1ca54e831725a66901b1b08f5b88892dbcd5
3
+ metadata.gz: 89ee711adf3ed85bc5e76210ee63f1d099431b6c
4
+ data.tar.gz: 276d832683ea7c659cb1f212b89043379aad50b6
5
5
  SHA512:
6
- metadata.gz: a013042da9ae780192a3f2808eff3343f0a5072cf2831b79432b1375098903eef6fee9a5da6d27e644ecbcaaa27b036e5e2a79b0bae1334c876623276c295c17
7
- data.tar.gz: d5346caa17e4911bbac88de74352dff4eb82781bec50f6410f48cc452824cd1935188c39427132b92fa61184e42c9450cd6203577d202982eb089a5600c8ef03
6
+ metadata.gz: 8f5e0e09b3647a84205a5d20b0a580348aaed0d0d2fcbb1df54c5aad818175628346ff41beb4798643c76e0521e1487c29951c978cf182b1e165a892c2777bf4
7
+ data.tar.gz: 7d04ea50400e63f0cd58c3013a25a6ff1905dfc1a11fd0991fc40e93a01742702cfe2e0dde76c81f93106cec5327f4b23884c208da40770dd265a7153cce9795
data/LE.gemspec CHANGED
@@ -5,7 +5,7 @@ require 'le'
5
5
 
6
6
  Gem::Specification.new do |gem|
7
7
  gem.name = "le"
8
- gem.version = "2.5.0"
8
+ gem.version = "2.6.0"
9
9
  gem.date = Time.now
10
10
  gem.summary = "Logentries plugin"
11
11
  gem.licenses = ["MIT"]
data/README.md CHANGED
@@ -23,7 +23,8 @@ Howto
23
23
  You must first register your account details with Logentries.
24
24
 
25
25
  Once you have logged in to Logentries, create a new host with a name of your choice.
26
- Inside this host, create a new logfile, selecting `Token TCP` as the source type.
26
+ Inside this host, create a new logfile, selecting `Token TCP` (or `Plain TCP/UDP` if using UDP)
27
+ as the source type.
27
28
 
28
29
  Heroku
29
30
  ------
@@ -73,10 +74,14 @@ You can also specify the default level of the logger by adding a :
73
74
 
74
75
  Rails.logger = Le.new('LOGENTRIES_TOKEN', :log_level => Logger::<level>)
75
76
 
76
- For the `LOGENTRIES_TOKEN` argument, paste the token for the logfile you created earlier in the Logentries UI.
77
+ For the `LOGENTRIES_TOKEN` argument, paste the token for the logfile you created earlier in the Logentries UI or empty string for
78
+ a UDP connection. Additionally, when connecting via UDP, be sure to specify a port using the udp_port parameter:
77
79
 
80
+ Rails.logger = Le.new('', :udp_port => 13287)
78
81
 
79
- Step for setting up DataHub
82
+
83
+
84
+ Step for setting up DataHub
80
85
  ---------------------------
81
86
 
82
87
  **datahub_endpoint - User Defined Array**
@@ -100,7 +105,7 @@ Enter_host_id inside the quotation marks. Leaving this empty leave the host_id
100
105
 
101
106
  **custom_host_name - User Defined Array**
102
107
 
103
- custom_host = Array[ true, "mikes_app_server"]
108
+ custom_host = Array[ true, "mikes_app_server"]
104
109
  The 1st parameter is a Boolean value to use the custom host name.
105
110
  The 2nd parameter is a String which is the custom_host_name you'd like to assign.
106
111
 
data/lib/le.rb CHANGED
@@ -20,12 +20,13 @@ module Le
20
20
  opt_host_name_enabled = options[:host_name_enabled] || false
21
21
  opt_host_name = options[:host_name] || ''
22
22
  opt_custom_host = options[:custom_host] || [false, '']
23
-
24
23
 
25
- self.checkParams(token, opt_datahub_enabled)
24
+ opt_udp_port = options[:udp_port] || nil
26
25
 
26
+ self.checkParams(token, opt_datahub_enabled, opt_udp_port)
27
27
 
28
- host = Le::Host.new(token, opt_local, opt_debug, opt_ssl, opt_datahub_endpoint, opt_host_id, opt_custom_host)
28
+
29
+ host = Le::Host.new(token, opt_local, opt_debug, opt_ssl, opt_datahub_endpoint, opt_host_id, opt_custom_host, opt_udp_port)
29
30
 
30
31
  if defined?(ActiveSupport::TaggedLogging) && opt_tag
31
32
  logger = ActiveSupport::TaggedLogging.new(Logger.new(host))
@@ -42,16 +43,16 @@ module Le
42
43
  logger
43
44
  end
44
45
 
45
- def self.checkParams(token, opt_datahub_enabled)
46
+ def self.checkParams(token, opt_datahub_enabled, opt_udp_port)
46
47
  # Check if the key is valid UUID format
47
48
 
48
- if (!opt_datahub_enabled) # test Token only when DataHub is not enabled
49
+ if (!opt_datahub_enabled && !opt_udp_port) # test Token only when DataHub and UDP are not enabled
49
50
  if (token =~ /\A(urn:uuid:)?[\da-f]{8}-([\da-f]{4}-){3}[\da-f]{12}\z/i) == nil
50
51
  puts "\nLE: It appears the LOGENTRIES_TOKEN you entered is invalid!\n"
51
52
  else
52
53
  (token="")
53
54
  end
54
- end
55
+ end
55
56
  end
56
57
 
57
58
  end
@@ -2,9 +2,9 @@ module Le
2
2
  module Host
3
3
 
4
4
  #! def self.new(token, local, debug, ssl, datahub_enabled, datahub_ip, datahub_port, host_id, host_name_enabled, host_name)
5
- def self.new(token, local, debug, ssl, datahub_endpoint, host_id, custom_host)
5
+ def self.new(token, local, debug, ssl, datahub_endpoint, host_id, custom_host, udp_port)
6
6
 
7
- Le::Host::HTTP.new(token, local, debug, ssl, datahub_endpoint, host_id, custom_host)
7
+ Le::Host::HTTP.new(token, local, debug, ssl, datahub_endpoint, host_id, custom_host, udp_port)
8
8
  end
9
9
 
10
10
  module InstanceMethods
@@ -50,10 +50,10 @@ S5ol3bQmY1mv78XKkOk=
50
50
 
51
51
  include Le::Host::InstanceMethods
52
52
  #! attr_accessor :token, :queue, :started, :thread, :conn, :local, :debug, :ssl, :datahub_enabled, :dathub_ip, :datahub_port, :host_id, :custom_host, :host_name_enabled, :host_name
53
- attr_accessor :token, :queue, :started, :thread, :conn, :local, :debug, :ssl, :datahub_enabled, :datahub_ip, :datahub_port, :datahub_endpoint, :host_id, :host_name_enabled, :host_name, :custom_host
53
+ attr_accessor :token, :queue, :started, :thread, :conn, :local, :debug, :ssl, :datahub_enabled, :datahub_ip, :datahub_port, :datahub_endpoint, :host_id, :host_name_enabled, :host_name, :custom_host, :udp_port
54
54
 
55
55
 
56
- def initialize(token, local, debug, ssl, datahub_endpoint, host_id, custom_host)
56
+ def initialize(token, local, debug, ssl, datahub_endpoint, host_id, custom_host, udp_port)
57
57
  if local
58
58
  device = if local.class <= TrueClass
59
59
  if defined?(Rails)
@@ -66,24 +66,25 @@ S5ol3bQmY1mv78XKkOk=
66
66
  end
67
67
  @logger_console = Logger.new(device)
68
68
  end
69
-
69
+
70
70
  @local = !!local
71
- @debug= debug
71
+ @debug= debug
72
72
  @ssl = ssl
73
+ @udp_port = udp_port
73
74
 
74
75
  @datahub_endpoint = datahub_endpoint
75
- if !@datahub_endpoint[0].empty?
76
+ if !@datahub_endpoint[0].empty?
76
77
  @datahub_enabled=true
77
78
  @datahub_ip="#{@datahub_endpoint[0]}"
78
79
  @datahub_port=@datahub_endpoint[1]
79
80
  else
80
- @datahub_enabled=false
81
+ @datahub_enabled=false
81
82
  end
82
83
 
83
84
 
84
85
  if (@datahub_enabled && @ssl)
85
86
  puts ("\n\nYou Cannot have DataHub and SSL enabled at the same time. Please set SSL value to false in your environment.rb file or used Token-Based logging by leaving the Datahub IP address blank. Exiting application. \n\n")
86
- exit
87
+ exit
87
88
  end
88
89
 
89
90
 
@@ -93,20 +94,20 @@ S5ol3bQmY1mv78XKkOk=
93
94
  else
94
95
  @token = ''
95
96
 
96
- #! NOTE THIS @datahub_port conditional MAY NEED TO BE CHANGED IF SSL CAN'T WORK WITH DH
97
+ #! NOTE THIS @datahub_port conditional MAY NEED TO BE CHANGED IF SSL CAN'T WORK WITH DH
97
98
  @datahub_port = @datahub_port.empty? ? API_SSL_PORT : datahub_port
98
99
  @datahub_ip = datahub_ip
99
100
  end
100
101
 
101
102
  @host_name_enabled=custom_host[0];
102
103
  @host_name= custom_host[1];
103
-
104
+
104
105
 
105
106
  # Check if host_id is empty -- if not assign, if so, make it an empty string.
106
107
  if !host_id.empty?
107
108
  @host_id = host_id
108
109
  @host_id = "host_id=#{host_id}"
109
- else
110
+ else
110
111
  @host_id=''
111
112
  end
112
113
 
@@ -150,7 +151,7 @@ S5ol3bQmY1mv78XKkOk=
150
151
 
151
152
  def write(message)
152
153
 
153
- if !host_id.empty?
154
+ if !host_id.empty?
154
155
  message = "#{message} #{ host_id }"
155
156
  end
156
157
 
@@ -163,7 +164,7 @@ S5ol3bQmY1mv78XKkOk=
163
164
  end
164
165
 
165
166
  if message.scan(/\n/).empty?
166
- @queue << "#{ @token } #{ message } \n"
167
+ @queue << "#{ @token } #{ message } \n"
167
168
  else
168
169
  @queue << "#{ message.gsub(/^/, "\1#{ @token } [#{ random_message_id }]") }\n"
169
170
  end
@@ -195,27 +196,36 @@ S5ol3bQmY1mv78XKkOk=
195
196
 
196
197
  def openConnection
197
198
  dbg "LE: Reopening connection to Logentries API server"
198
-
199
199
 
200
- if !@datahub_enabled
201
- port = @ssl ? API_SSL_PORT: API_PORT
202
- socket = TCPSocket.new(API_SERVER, port)
203
- else
200
+ if @udp_port
201
+ host = API_SERVER
202
+ port = @udp_port
203
+ elsif @datahub_enabled
204
+ host = @datahub_ip
204
205
  port = @datahub_port
205
- socket = TCPSocket.new(@datahub_ip, port)
206
+ else
207
+ host = API_SERVER
208
+ port = @ssl ? API_SSL_PORT: API_PORT
206
209
  end
207
210
 
208
-
209
- if @ssl
210
- ssl_context = OpenSSL::SSL::SSLContext.new()
211
- ssl_context.cert = OpenSSL::X509::Certificate.new(API_CERT)
212
- ssl_socket = OpenSSL::SSL::SSLSocket.new(socket, ssl_context)
213
- ssl_socket.sync_close = true
214
- ssl_socket.connect
215
- @conn = ssl_socket
211
+ if @udp_port
212
+ @conn = UDPSocket.new
213
+ @conn.connect(host, port)
216
214
  else
217
- @conn = socket
215
+ socket = TCPSocket.new(host, port)
216
+
217
+ if @ssl
218
+ ssl_context = OpenSSL::SSL::SSLContext.new()
219
+ ssl_context.cert = OpenSSL::X509::Certificate.new(API_CERT)
220
+ ssl_socket = OpenSSL::SSL::SSLSocket.new(socket, ssl_context)
221
+ ssl_socket.sync_close = true
222
+ ssl_socket.connect
223
+ @conn = ssl_socket
224
+ else
225
+ @conn = socket
226
+ end
218
227
  end
228
+
219
229
  dbg "LE: Connection established"
220
230
  end
221
231
 
@@ -265,7 +275,7 @@ S5ol3bQmY1mv78XKkOk=
265
275
  loop do
266
276
  begin
267
277
  @conn.write(data)
268
- rescue TimeoutError, Errno::EHOSTUNREACH, Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::ETIMEOUT, EOFError
278
+ rescue TimeoutError, Errno::EHOSTUNREACH, Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::ETIMEDOUT, EOFError
269
279
  dbg "LE: Connection timeout(#{ $! }), try to reopen connection"
270
280
  reopenConnection
271
281
  next
@@ -6,13 +6,14 @@ describe Le::Host do
6
6
  let(:local) { false }
7
7
  let(:debug) { false }
8
8
  let(:ssl) { false }
9
+ let(:udp_port){ nil }
9
10
 
10
11
  let(:datahub_endpoint) { ["", 10000] }
11
12
  let(:host_id) { ""}
12
13
  let(:custom_host) { [false, ""]}
13
14
 
14
15
  #let(:host) { Le::Host.new(token, local, debug, ssl) }
15
- let(:host) { Le::Host.new(token, local, debug, ssl, datahub_endpoint, host_id, custom_host)}
16
+ let(:host) { Le::Host.new(token, local, debug, ssl, datahub_endpoint, host_id, custom_host, udp_port)}
16
17
  specify { host.must_be_instance_of Le::Host::HTTP }
17
18
 
18
19
  end
@@ -7,14 +7,15 @@ describe Le::Host::HTTP do
7
7
  let(:local) { false }
8
8
  let(:debug) { false }
9
9
  let(:ssl) { false }
10
+ let(:udp) { nil }
10
11
 
11
12
  let(:datahub_endpoint) { ["", 10000]}
12
13
  let(:host_id) {""}
13
14
  let(:custom_host) {[false, ""]}
14
-
15
+
15
16
 
16
17
  # let(:host) { Le::Host::HTTP.new(token, local, debug, ssl) }
17
- let(:host) { Le::Host::HTTP.new(token, local, debug, ssl, datahub_endpoint, host_id, custom_host) }
18
+ let(:host) { Le::Host::HTTP.new(token, local, debug, ssl, datahub_endpoint, host_id, custom_host, udp) }
18
19
 
19
20
  let(:logger_console) { host.instance_variable_get(:@logger_console) }
20
21
  let(:logger_console_dev) { logger_console.instance_variable_get(:@logdev).dev }
@@ -23,7 +24,8 @@ describe Le::Host::HTTP do
23
24
  specify { host.local.must_equal false }
24
25
  specify { host.debug.must_equal false }
25
26
  specify { host.ssl.must_equal false }
27
+ specify { host.udp_port.must_equal nil }
26
28
  specify {host_id.must_equal ""}
27
- specify {custom_host.must_equal [false, ""]}
29
+ specify {custom_host.must_equal [false, ""]}
28
30
 
29
31
  end
@@ -59,7 +59,7 @@ describe Le do
59
59
  end
60
60
 
61
61
  describe "File" do
62
- let(:log_file) { File.new(local_test_log) }
62
+ let(:log_file) { File.new(local_test_log, 'w') }
63
63
 
64
64
  specify { logdev.must_be_instance_of Le::Host::HTTP }
65
65
  specify { logdev.local.must_equal true }
@@ -126,7 +126,7 @@ describe Le do
126
126
  end
127
127
 
128
128
  describe "File" do
129
- let(:log_file) { File.new(local_test_log) }
129
+ let(:log_file) { File.new(local_test_log, 'w') }
130
130
 
131
131
  specify { logdev.must_be_instance_of Le::Host::HTTP }
132
132
  specify { logdev.local.must_equal true }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: le
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.0
4
+ version: 2.6.0
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-10-09 00:00:00.000000000 Z
11
+ date: 2014-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler