le 2.4.0 → 2.5.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: 6c28e499c3453e636efe4c437f2ad4c0ab1b0fc0
4
- data.tar.gz: b276ef975d89403e9d8d59803ec23abe64354e61
3
+ metadata.gz: 8106a0e740c344c588e5bfb06acb2d55af4d5437
4
+ data.tar.gz: 2b9b1ca54e831725a66901b1b08f5b88892dbcd5
5
5
  SHA512:
6
- metadata.gz: f0b91de7609636128de8d0074c5148c783159b96d7d201ecea101941109ddd3bbaf54e8fb1166b55fd3b50f613ac1b7833416c568b0f62e19029b138bd204f31
7
- data.tar.gz: e78ba124558eb27feb271ef5d15b6db53e73c46e717c44467d5abe4186961b345e8c2640c05be2365ff86279e52e70d775a4ad8c7cb66cbf1d7872dcc9b5431f
6
+ metadata.gz: a013042da9ae780192a3f2808eff3343f0a5072cf2831b79432b1375098903eef6fee9a5da6d27e644ecbcaaa27b036e5e2a79b0bae1334c876623276c295c17
7
+ data.tar.gz: d5346caa17e4911bbac88de74352dff4eb82781bec50f6410f48cc452824cd1935188c39427132b92fa61184e42c9450cd6203577d202982eb089a5600c8ef03
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.4.0"
8
+ gem.version = "2.5.0"
9
9
  gem.date = Time.now
10
10
  gem.summary = "Logentries plugin"
11
11
  gem.licenses = ["MIT"]
data/README.md CHANGED
@@ -41,7 +41,8 @@ Then from the cmd line run the following command:
41
41
  This will install the gem on your local environment.
42
42
 
43
43
  The next step is to configure the default rails logger to use the logentries
44
- logger.
44
+ logger.
45
+
45
46
 
46
47
  In your environment configuration file ( for production : `config/environments/production.rb`), add the following:
47
48
 
@@ -74,4 +75,42 @@ You can also specify the default level of the logger by adding a :
74
75
 
75
76
  For the `LOGENTRIES_TOKEN` argument, paste the token for the logfile you created earlier in the Logentries UI.
76
77
 
78
+
79
+ Step for setting up DataHub
80
+ ---------------------------
81
+
82
+ **datahub_endpoint - User Defined Array**
83
+
84
+ datahub_endpoint = Array ["127.0.0.1", "10000"]
85
+ datahub_endpoint is a user defined variable array for a datahub_endpoint
86
+ The 1st parameter is a String which is the DataHub Instance's IP Address. Entering ANY value in this field will disable your Token-based
87
+ logging, set your Token to "" and will direct all log events to your specified DataHub IP Address.
88
+
89
+ The 2nd parameter is a String which is the DataHub Port value, default is 10000 but this can be changed on your DataHub Machine.
90
+ This port number must be set, on your DataHub Machine's leproxy settings your /etc/leproxy/leproxyLocal.config file. It's default is 10000
91
+ NOTE: if datahub_endpoint has been assigned an IP address and SSL = true, your server will fail gracefully.
92
+ When using Datahub do not enable SSL = true
93
+
94
+
95
+ **host_id**
96
+
97
+ host_id = "abc1234"
98
+ Enter_host_id inside the quotation marks. Leaving this empty leave the host_id empty and thus not appear in your log events.
99
+
100
+
101
+ **custom_host_name - User Defined Array**
102
+
103
+ custom_host = Array[ true, "mikes_app_server"]
104
+ The 1st parameter is a Boolean value to use the custom host name.
105
+ The 2nd parameter is a String which is the custom_host_name you'd like to assign.
106
+
107
+ If the 2nd parameter is left as in custom_host = Array[ true, ""] the code will attempt to get your host machine's name using the socket.gethostname method.
108
+
109
+
110
+
111
+ Using the above user defined variable settings, you can now also specify the several of the optional arguments for the logger constructor by adding:
112
+
113
+ Rails.logger = Le.new(token, :ssl=>ssl, :datahub_endpoint=>datahub_endpoint, :host_id=>host_id, :custom_host=>custom_host)
114
+
115
+
77
116
  Now, simply use `Rails.logger.info("message")` inside your code to send logs to Logentries
data/lib/le.rb CHANGED
@@ -6,15 +6,26 @@ module Le
6
6
 
7
7
  def self.new(token, options={})
8
8
 
9
- self.checkParams(token)
9
+ opt_local = options[:local] || false
10
+ opt_debug = options[:debug] || false
11
+ opt_ssl = options[:ssl] || false
12
+ opt_tag = options[:tag] || false
13
+ opt_log_level = options[:log_level] || Logger::DEBUG
10
14
 
11
- opt_local = options[:local] || false
12
- opt_debug = options[:debug] || false
13
- opt_ssl = options[:ssl] || false
14
- opt_tag = options[:tag] || false
15
- opt_log_level = options[:log_level] || Logger::DEBUG
15
+ opt_datahub_enabled = options[:datahub_enabled] || false
16
+ opt_datahub_endpoint = options[:datahub_endpoint] || ['', 10000]
17
+ opt_datahub_ip = options[:datahub_ip] || ''
18
+ opt_datahub_port = options[:datahub_port] || 10000
19
+ opt_host_id = options[:host_id] || ''
20
+ opt_host_name_enabled = options[:host_name_enabled] || false
21
+ opt_host_name = options[:host_name] || ''
22
+ opt_custom_host = options[:custom_host] || [false, '']
23
+
16
24
 
17
- host = Le::Host.new(token, opt_local, opt_debug, opt_ssl)
25
+ self.checkParams(token, opt_datahub_enabled)
26
+
27
+
28
+ host = Le::Host.new(token, opt_local, opt_debug, opt_ssl, opt_datahub_endpoint, opt_host_id, opt_custom_host)
18
29
 
19
30
  if defined?(ActiveSupport::TaggedLogging) && opt_tag
20
31
  logger = ActiveSupport::TaggedLogging.new(Logger.new(host))
@@ -31,10 +42,16 @@ module Le
31
42
  logger
32
43
  end
33
44
 
34
- def self.checkParams(token)
45
+ def self.checkParams(token, opt_datahub_enabled)
35
46
  # Check if the key is valid UUID format
36
- if (token =~ /\A(urn:uuid:)?[\da-f]{8}-([\da-f]{4}-){3}[\da-f]{12}\z/i) == nil
37
- puts "\nLE: It appears the LOGENTRIES_TOKEN you entered is invalid!\n"
38
- end
47
+
48
+ if (!opt_datahub_enabled) # test Token only when DataHub is not enabled
49
+ if (token =~ /\A(urn:uuid:)?[\da-f]{8}-([\da-f]{4}-){3}[\da-f]{12}\z/i) == nil
50
+ puts "\nLE: It appears the LOGENTRIES_TOKEN you entered is invalid!\n"
51
+ else
52
+ (token="")
53
+ end
54
+ end
39
55
  end
56
+
40
57
  end
@@ -1,8 +1,10 @@
1
1
  module Le
2
2
  module Host
3
3
 
4
- def self.new(token, local, debug, ssl)
5
- Le::Host::HTTP.new(token, local, debug, ssl)
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)
6
+
7
+ Le::Host::HTTP.new(token, local, debug, ssl, datahub_endpoint, host_id, custom_host)
6
8
  end
7
9
 
8
10
  module InstanceMethods
@@ -7,7 +7,9 @@ module Le
7
7
  module Host
8
8
  class HTTP
9
9
  LIBRARY_IDENTIFIER = '###R01### - Library initialised'
10
+ # API_SERVER = 'api.logentries.com'
10
11
  API_SERVER = 'api.logentries.com'
12
+
11
13
  API_PORT = 10000
12
14
  API_SSL_PORT = 20000
13
15
  API_CERT = '-----BEGIN CERTIFICATE-----
@@ -47,25 +49,79 @@ S5ol3bQmY1mv78XKkOk=
47
49
 
48
50
 
49
51
  include Le::Host::InstanceMethods
50
- attr_accessor :token, :queue, :started, :thread, :conn, :local, :debug, :ssl
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
54
+
51
55
 
52
- def initialize(token, local, debug, ssl)
53
- if local
54
- device = if local.class <= TrueClass
55
- if defined?(Rails)
56
- Rails.root.join("log","#{Rails.env}.log")
56
+ def initialize(token, local, debug, ssl, datahub_endpoint, host_id, custom_host)
57
+ if local
58
+ device = if local.class <= TrueClass
59
+ if defined?(Rails)
60
+ Rails.root.join("log","#{Rails.env}.log")
61
+ else
62
+ STDOUT
63
+ end
57
64
  else
58
- STDOUT
59
- end
60
- else
61
65
  local
62
- end
66
+ end
63
67
  @logger_console = Logger.new(device)
68
+ end
69
+
70
+ @local = !!local
71
+ @debug= debug
72
+ @ssl = ssl
73
+
74
+ @datahub_endpoint = datahub_endpoint
75
+ if !@datahub_endpoint[0].empty?
76
+ @datahub_enabled=true
77
+ @datahub_ip="#{@datahub_endpoint[0]}"
78
+ @datahub_port=@datahub_endpoint[1]
79
+ else
80
+ @datahub_enabled=false
81
+ end
82
+
83
+
84
+ if (@datahub_enabled && @ssl)
85
+ 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
64
87
  end
65
- @token = token
66
- @local = !!local
67
- @debug = debug
68
- @ssl = ssl
88
+
89
+
90
+ #check if DataHub is enabled... if datahub is not enabled, set the token to the token's parameter. If DH is enabled, make the token empty.
91
+ if (!datahub_enabled)
92
+ @token = token
93
+ else
94
+ @token = ''
95
+
96
+ #! NOTE THIS @datahub_port conditional MAY NEED TO BE CHANGED IF SSL CAN'T WORK WITH DH
97
+ @datahub_port = @datahub_port.empty? ? API_SSL_PORT : datahub_port
98
+ @datahub_ip = datahub_ip
99
+ end
100
+
101
+ @host_name_enabled=custom_host[0];
102
+ @host_name= custom_host[1];
103
+
104
+
105
+ # Check if host_id is empty -- if not assign, if so, make it an empty string.
106
+ if !host_id.empty?
107
+ @host_id = host_id
108
+ @host_id = "host_id=#{host_id}"
109
+ else
110
+ @host_id=''
111
+ end
112
+
113
+
114
+
115
+ #assign host_name, if no host name is given and host_name_enabled = true... assign a host_name based on the machine name.
116
+ if @host_name_enabled
117
+ if host_name.empty?
118
+ @host_name=Socket.gethostname
119
+ end
120
+
121
+ @host_name="host_name=#{@host_name}"
122
+ end
123
+
124
+
69
125
  @queue = Queue.new
70
126
  # Add identifer msg to queue to be sent first
71
127
  @queue << "#{@token}#{LIBRARY_IDENTIFIER}\n"
@@ -93,14 +149,23 @@ S5ol3bQmY1mv78XKkOk=
93
149
  end
94
150
 
95
151
  def write(message)
152
+
153
+ if !host_id.empty?
154
+ message = "#{message} #{ host_id }"
155
+ end
156
+
157
+ if host_name_enabled
158
+ message="#{message} #{ host_name }"
159
+ end
160
+
96
161
  if @local
97
162
  @logger_console.add(Logger::Severity::UNKNOWN, message)
98
163
  end
99
164
 
100
165
  if message.scan(/\n/).empty?
101
- @queue << "#{ @token } #{ message }\n"
166
+ @queue << "#{ @token } #{ message } \n"
102
167
  else
103
- @queue << "#{ message.gsub(/^/, "\1#{ @token } [#{ random_message_id }] ") }\n"
168
+ @queue << "#{ message.gsub(/^/, "\1#{ @token } [#{ random_message_id }]") }\n"
104
169
  end
105
170
 
106
171
 
@@ -130,8 +195,17 @@ S5ol3bQmY1mv78XKkOk=
130
195
 
131
196
  def openConnection
132
197
  dbg "LE: Reopening connection to Logentries API server"
133
- port = @ssl ? API_SSL_PORT : API_PORT
134
- socket = TCPSocket.new(API_SERVER, port)
198
+
199
+
200
+ if !@datahub_enabled
201
+ port = @ssl ? API_SSL_PORT: API_PORT
202
+ socket = TCPSocket.new(API_SERVER, port)
203
+ else
204
+ port = @datahub_port
205
+ socket = TCPSocket.new(@datahub_ip, port)
206
+ end
207
+
208
+
135
209
  if @ssl
136
210
  ssl_context = OpenSSL::SSL::SSLContext.new()
137
211
  ssl_context.cert = OpenSSL::X509::Certificate.new(API_CERT)
@@ -191,7 +265,7 @@ S5ol3bQmY1mv78XKkOk=
191
265
  loop do
192
266
  begin
193
267
  @conn.write(data)
194
- rescue TimeoutError, Errno::EHOSTUNREACH, Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::ETIMEDOUT, EOFError
268
+ rescue TimeoutError, Errno::EHOSTUNREACH, Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::ETIMEOUT, EOFError
195
269
  dbg "LE: Connection timeout(#{ $! }), try to reopen connection"
196
270
  reopenConnection
197
271
  next
@@ -6,8 +6,13 @@ describe Le::Host do
6
6
  let(:local) { false }
7
7
  let(:debug) { false }
8
8
  let(:ssl) { false }
9
- let(:host) { Le::Host.new(token, local, debug, ssl) }
10
9
 
10
+ let(:datahub_endpoint) { ["", 10000] }
11
+ let(:host_id) { ""}
12
+ let(:custom_host) { [false, ""]}
13
+
14
+ #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)}
11
16
  specify { host.must_be_instance_of Le::Host::HTTP }
12
17
 
13
18
  end
@@ -7,7 +7,15 @@ describe Le::Host::HTTP do
7
7
  let(:local) { false }
8
8
  let(:debug) { false }
9
9
  let(:ssl) { false }
10
- let(:host) { Le::Host::HTTP.new(token, local, debug, ssl) }
10
+
11
+ let(:datahub_endpoint) { ["", 10000]}
12
+ let(:host_id) {""}
13
+ let(:custom_host) {[false, ""]}
14
+
15
+
16
+ # 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
+
11
19
  let(:logger_console) { host.instance_variable_get(:@logger_console) }
12
20
  let(:logger_console_dev) { logger_console.instance_variable_get(:@logdev).dev }
13
21
 
@@ -15,5 +23,7 @@ describe Le::Host::HTTP do
15
23
  specify { host.local.must_equal false }
16
24
  specify { host.debug.must_equal false }
17
25
  specify { host.ssl.must_equal false }
26
+ specify {host_id.must_equal ""}
27
+ specify {custom_host.must_equal [false, ""]}
18
28
 
19
29
  end
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.4.0
4
+ version: 2.5.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-09-30 00:00:00.000000000 Z
11
+ date: 2014-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler