jlog-rails 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -23,6 +23,8 @@ On the client-side:
23
23
  Changelog:
24
24
  ----------
25
25
 
26
+ * 0.0.3
27
+ * Adding bulk flush in the ajax appender
26
28
  * 0.0.2
27
29
  * Changed format of output message
28
30
  * InstallGenerator now updates application.js
@@ -32,4 +34,4 @@ Changelog:
32
34
  * Moved to AjaxController ActionController::Metal
33
35
  * Added support for server-side logging of client events with Rails.logger
34
36
  * Added AjaxAppender
35
- * Initial port of jlog.js
37
+ * Initial port of jlog.js
@@ -4,16 +4,19 @@ module Jlog
4
4
  include ActionController::Rendering
5
5
 
6
6
  def append
7
- message = params[:message]
8
- level_pattern = /^(DEBUG|INFO|WARN|ERROR|FATAL)/
9
- level = message.match(level_pattern)[1]
10
- message = 'Client ' << message
7
+ messages = params[:message]
8
+ messages = [message] unless messages.is_a? Array
9
+ messages.each do |message|
10
+ level_pattern = /^(DEBUG|INFO|WARN|ERROR|FATAL)/
11
+ level = message.match(level_pattern)[1]
12
+ message = 'Client ' << message
11
13
 
12
- if ['DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL'].include? level
13
- Rails.logger.send(level.downcase.to_sym, message)
14
- else
15
- Rails.logger.warn('*** Attempt to log with a nonexistent level ***')
16
- Rails.logger.warn(message)
14
+ if ['DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL'].include? level
15
+ Rails.logger.send(level.downcase.to_sym, message)
16
+ else
17
+ Rails.logger.warn('*** Attempt to log with a nonexistent level ***')
18
+ Rails.logger.warn(message)
19
+ end
17
20
  end
18
21
 
19
22
  render text: 'ok', status: :ok
@@ -21,4 +24,4 @@ module Jlog
21
24
 
22
25
  end
23
26
 
24
- end
27
+ end
data/jlog-rails.gemspec CHANGED
@@ -4,11 +4,11 @@ require File.expand_path("lib/jlog/version")
4
4
  Gem::Specification.new do |s|
5
5
  s.name = 'jlog-rails'
6
6
  s.version = Jlog::VERSION
7
- s.date = '2012-08-31'
7
+ s.date = '2012-10-18'
8
8
  s.summary = "Jlog for Rails"
9
9
  s.description = "A lightweight JavaScript logger (for Rails)"
10
- s.authors = ["Alexey Golubev"]
11
- s.email = 'oholubyev@heliostech.hk'
10
+ s.authors = ["Helios Technologies Ltd."]
11
+ s.email = 'contact@heliostech.fr'
12
12
  s.files = `git ls-files`.split("\n")
13
13
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
14
  s.homepage = 'http://rubygems.org/gems/jlog-rails'
@@ -16,4 +16,4 @@ Gem::Specification.new do |s|
16
16
  s.rubyforge_project = "jlog-rails"
17
17
 
18
18
  s.add_dependency "jquery-rails"
19
- end
19
+ end
data/lib/jlog/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Jlog
2
- VERSION = '0.0.2'
3
- end
2
+ VERSION = '0.0.3'
3
+ end
@@ -26,7 +26,7 @@
26
26
 
27
27
  /**
28
28
  *
29
- * @remixer Alexey Golubev mailto:oholubyev@heliostech.hk
29
+ * @remixer Helios Technologies Ltd. mailto:contact@heliostech.fr
30
30
  *
31
31
  **/
32
32
 
@@ -125,6 +125,8 @@ JLog.ERROR = 4;
125
125
  JLog.FATAL = 5;
126
126
  JLog.NONE = 6;
127
127
 
128
+ JLog.VERSION = "0.0.3b3";
129
+
128
130
  JLog.prototype.debug = function() {
129
131
  if (this.getLevel() <= JLog.DEBUG) {
130
132
  this._log("DEBUG", arguments);
@@ -189,13 +191,72 @@ JLog.ConsoleAppender = function() {
189
191
  };
190
192
 
191
193
  JLog.AjaxAppender = function(url) {
192
- var _url = url;
194
+ // Do we make more then 1 call at a time?
195
+ var waitForResponse = true;
196
+ // Current buffer of messages
197
+ var queuedLoggingEvents = [];
198
+ // Messages which should be sent
199
+ var queuedRequests = [];
200
+ // Maximum count of messages sent at a one time
201
+ var batchSize = 10;
202
+ // Are we currently sending something
203
+ var sending = false;
204
+ // Timeout between sending data
205
+ var timerInterval = 1000;
206
+
207
+ function scheduleSending() {
208
+ window.setTimeout(sendAllRemaining, timerInterval);
209
+ }
210
+
211
+ function sendRequest(postData, callback) {
212
+ $.post(url, postData, "json")
213
+ .complete(function() {
214
+ if(waitForResponse) sending = false;
215
+ if (callback) callback(true);
216
+ });
217
+ }
218
+
219
+ function sendAllRemaining() {
220
+ if(queuedLoggingEvents.length == 0) return;
221
+ var eventCopy = queuedLoggingEvents;
222
+ queuedLoggingEvents = [];
223
+ queuedRequests.push(eventCopy);
224
+ sendAll();
225
+ }
226
+
227
+ function preparePostData(data) { return { message:data }; }
228
+
229
+ function sendAll() {
230
+ if(waitForResponse && sending) return;
231
+ sending = true;
232
+ var currentRequestBatch;
233
+ if (waitForResponse) {
234
+ if (queuedRequests.length > 0) {
235
+ currentRequestBatch = queuedRequests.shift();
236
+ sendRequest(preparePostData(currentRequestBatch), sendAll);
237
+ } else {
238
+ sending = false;
239
+ scheduleSending();
240
+ }
241
+ } else {
242
+ // Rattle off all the requests without waiting to see the response
243
+ while ((currentRequestBatch = queuedRequests.shift())) {
244
+ sendRequest(preparePostData(currentRequestBatch));
245
+ }
246
+ sending = false;
247
+ scheduleSending();
248
+ }
249
+ }
250
+
251
+ scheduleSending();
193
252
 
194
253
  return {
195
254
  name: 'AjaxAppender',
196
255
 
197
256
  log: function(msg) {
198
- $.post(_url, {message: msg});
257
+ queuedLoggingEvents.push(msg);
258
+ if (queuedLoggingEvents.length >= batchSize) sendAllRemaining();
259
+ else if(queuedLoggingEvents.length == 1) scheduleSending();
199
260
  }
200
261
  }
201
- };
262
+ };
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jlog-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
- - Alexey Golubev
8
+ - Helios Technologies Ltd.
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-31 00:00:00.000000000 Z
12
+ date: 2012-10-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jquery-rails
@@ -28,7 +28,7 @@ dependencies:
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
30
  description: A lightweight JavaScript logger (for Rails)
31
- email: oholubyev@heliostech.hk
31
+ email: contact@heliostech.fr
32
32
  executables: []
33
33
  extensions: []
34
34
  extra_rdoc_files: []
@@ -67,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
67
  version: '0'
68
68
  requirements: []
69
69
  rubyforge_project: jlog-rails
70
- rubygems_version: 1.8.22
70
+ rubygems_version: 1.8.23
71
71
  signing_key:
72
72
  specification_version: 3
73
73
  summary: Jlog for Rails