jlog-rails 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +8 -1
- data/Rakefile +11 -1
- data/app/controllers/jlog/ajax_controller.rb +4 -4
- data/jlog-rails.gemspec +1 -0
- data/lib/jlog/version.rb +1 -1
- data/test/ajax-appender-test.js +22 -0
- data/test/buster.js +28 -0
- data/test/lib/jquery-1.9.1.min.js +5 -0
- data/test/lib/underscore.js +1226 -0
- data/test/logger-test.js +49 -0
- data/test/pattern-layout-test.js +37 -0
- data/vendor/assets/javascripts/appender.js +93 -0
- data/vendor/assets/javascripts/appenders/ajax.js +151 -0
- data/vendor/assets/javascripts/appenders/console.js +20 -0
- data/vendor/assets/javascripts/jlog.js +11 -236
- data/vendor/assets/javascripts/layout.js +216 -0
- data/vendor/assets/javascripts/layouts/pattern.js +184 -0
- data/vendor/assets/javascripts/levels.js +35 -0
- data/vendor/assets/javascripts/logger.js +370 -0
- data/vendor/assets/javascripts/logging_event.js +81 -0
- data/vendor/assets/javascripts/mount.js +4 -0
- metadata +38 -3
@@ -0,0 +1,370 @@
|
|
1
|
+
(function(JLog){
|
2
|
+
var anonymousLoggerName = "[anonymous]";
|
3
|
+
var defaultLoggerName = "[default]";
|
4
|
+
var rootLoggerName = "root";
|
5
|
+
|
6
|
+
var loggers = {};
|
7
|
+
var loggerNames = [];
|
8
|
+
|
9
|
+
var rootLogger = new Logger(rootLoggerName);
|
10
|
+
var rootLoggerDefaultLevel = JLog.Level.DEBUG;
|
11
|
+
|
12
|
+
rootLogger.setLevel(rootLoggerDefaultLevel);
|
13
|
+
JLog.getRootLogger = function() {
|
14
|
+
return rootLogger;
|
15
|
+
};
|
16
|
+
|
17
|
+
var defaultLogger = null;
|
18
|
+
JLog.getDefaultLogger = function() {
|
19
|
+
if (!defaultLogger) defaultLogger = JLog.getLogger(defaultLoggerName);
|
20
|
+
return defaultLogger;
|
21
|
+
};
|
22
|
+
|
23
|
+
/*
|
24
|
+
Class: Logger
|
25
|
+
Manager of logged events.
|
26
|
+
*/
|
27
|
+
function Logger(name) {
|
28
|
+
this.parent = null;
|
29
|
+
this.children = [];
|
30
|
+
|
31
|
+
var _name = name;
|
32
|
+
var _appenders = [];
|
33
|
+
var _currentLevel = null;
|
34
|
+
var _isRoot = (_name === rootLoggerName);
|
35
|
+
var _enabled = true;
|
36
|
+
|
37
|
+
var _appenderCache = null;
|
38
|
+
var _appenderCacheInvalidated = false;
|
39
|
+
|
40
|
+
this.turnOn = function() { _enabled = true; };
|
41
|
+
this.turnOff = function() { _enabled = false; };
|
42
|
+
this.isOn = function() { return _enabled; };
|
43
|
+
|
44
|
+
this.getName = function() { return _name; }
|
45
|
+
|
46
|
+
var _additive = true;
|
47
|
+
/*
|
48
|
+
Method: getAdditivity
|
49
|
+
|
50
|
+
Get if log events are propagated higher in logger hierarchy.
|
51
|
+
|
52
|
+
Returns:
|
53
|
+
If events should be propagated higher.
|
54
|
+
|
55
|
+
See Also:
|
56
|
+
<setAdditivity>
|
57
|
+
*/
|
58
|
+
this.getAdditivity = function() { return _additive; };
|
59
|
+
|
60
|
+
/*
|
61
|
+
Method: setAdditivity
|
62
|
+
|
63
|
+
Set if log events are propagated higher in logger hierarchy.
|
64
|
+
|
65
|
+
Parameters:
|
66
|
+
additivity - if events should be propagated higher.
|
67
|
+
|
68
|
+
See Also:
|
69
|
+
<getAdditivity>
|
70
|
+
*/
|
71
|
+
this.setAdditivity = function(additivity) {
|
72
|
+
var valueChanged = (_additive != additivity);
|
73
|
+
_additive = additivity;
|
74
|
+
if(valueChanged) this._invalidateAppenderCache();
|
75
|
+
};
|
76
|
+
|
77
|
+
/*
|
78
|
+
Method: addChild
|
79
|
+
|
80
|
+
Makes given logger a child of current logger. If child is additive, all it's events will go through this logger
|
81
|
+
either.
|
82
|
+
|
83
|
+
Parameters:
|
84
|
+
childLogger - given logger.
|
85
|
+
*/
|
86
|
+
this.addChild = function(childLogger) {
|
87
|
+
this.children.push(childLogger);
|
88
|
+
childLogger.parent = this;
|
89
|
+
childLogger._invalidateAppenderCache();
|
90
|
+
};
|
91
|
+
|
92
|
+
/*
|
93
|
+
Method: addAppender
|
94
|
+
|
95
|
+
Push an appender for this logger.
|
96
|
+
|
97
|
+
Parameters:
|
98
|
+
appender - appender to push.
|
99
|
+
|
100
|
+
See Also:
|
101
|
+
<removeAppender>
|
102
|
+
<removeAllAppenders>
|
103
|
+
*/
|
104
|
+
this.addAppender = function(appender) {
|
105
|
+
if(_appenders.indexOf(appender) >= 0) return;
|
106
|
+
_appenders.push(appender);
|
107
|
+
this._invalidateAppenderCache();
|
108
|
+
};
|
109
|
+
|
110
|
+
/*
|
111
|
+
Method: removeAppender
|
112
|
+
|
113
|
+
Remove appender out of this logger.
|
114
|
+
|
115
|
+
Parameters:
|
116
|
+
appender - appender to remove.
|
117
|
+
|
118
|
+
See Also:
|
119
|
+
<addAppender>
|
120
|
+
<removeAllAppenders>
|
121
|
+
*/
|
122
|
+
this.removeAppender = function(appender) {
|
123
|
+
_appenders.splice(_appenders.indexOf(appender), 1);
|
124
|
+
this._invalidateAppenderCache();
|
125
|
+
};
|
126
|
+
|
127
|
+
/*
|
128
|
+
Method: removeAllAppender
|
129
|
+
|
130
|
+
Remove all appenders from this logger.
|
131
|
+
|
132
|
+
See Also:
|
133
|
+
<addAppender>
|
134
|
+
<removeAppender>
|
135
|
+
*/
|
136
|
+
this.removeAllAppenders = function() {
|
137
|
+
_appenders = [];
|
138
|
+
this._invalidateAppenderCache();
|
139
|
+
};
|
140
|
+
|
141
|
+
/*
|
142
|
+
Method: getEffectiveAppenders
|
143
|
+
|
144
|
+
Returns all appender which will log given message.
|
145
|
+
*/
|
146
|
+
this.getEffectiveAppenders = function() {
|
147
|
+
if (_appenderCache === null || _appenderCacheInvalidated) {
|
148
|
+
// Build appender cache
|
149
|
+
var parentEffectiveAppenders = (_isRoot || !this.getAdditivity()) ? [] : this.parent.getEffectiveAppenders();
|
150
|
+
_appenderCache = _.union(parentEffectiveAppenders, _appenders);
|
151
|
+
_appenderCacheInvalidated = false;
|
152
|
+
}
|
153
|
+
return _appenderCache;
|
154
|
+
};
|
155
|
+
|
156
|
+
this._invalidateAppenderCache = function() {
|
157
|
+
_appenderCacheInvalidated = true;
|
158
|
+
_.each(this.children, function(c) { c._invalidateAppenderCache(); });
|
159
|
+
};
|
160
|
+
|
161
|
+
/*
|
162
|
+
Method: log
|
163
|
+
|
164
|
+
Publish logger message across all the appenders! Prefer using specialized function instead.
|
165
|
+
|
166
|
+
Parameters:
|
167
|
+
level - <Level> of message event
|
168
|
+
params - array of message parts. first parameter is usually a simple message.
|
169
|
+
*/
|
170
|
+
this.log = function(level, params) {
|
171
|
+
try {
|
172
|
+
if(!(this.isOn() && level.isGreaterOrEqual(this._getEffectiveLevel()))) return;
|
173
|
+
|
174
|
+
params = Array.prototype.slice.call(params || []);
|
175
|
+
|
176
|
+
var exception;
|
177
|
+
var finalParamIndex = params.length - 1;
|
178
|
+
var lastParam = params[finalParamIndex];
|
179
|
+
if (params.length > 1 && (lastParam instanceof Error)) {
|
180
|
+
exception = lastParam;
|
181
|
+
--finalParamIndex;
|
182
|
+
}
|
183
|
+
|
184
|
+
var messages = finalParamIndex >= 0 ? params.slice(0, finalParamIndex + 1) : [];
|
185
|
+
|
186
|
+
var logEvent = new JLog.LoggingEvent(this, new Date(), level, messages, exception);
|
187
|
+
|
188
|
+
this._callAppenders(logEvent);
|
189
|
+
} catch(loggerError) {
|
190
|
+
JLog.handleError(loggerError);
|
191
|
+
// TODO deal with errors inside logger - user of the logger should not know about such a bugs, unless explicitly
|
192
|
+
// requested this!
|
193
|
+
}
|
194
|
+
};
|
195
|
+
|
196
|
+
this._callAppenders = function(logEvent) {
|
197
|
+
_.each(this.getEffectiveAppenders(), function(app) { app.doAppend(logEvent); });
|
198
|
+
};
|
199
|
+
|
200
|
+
/*
|
201
|
+
Method: setLevel
|
202
|
+
|
203
|
+
Set minimal level of log messages to populate.
|
204
|
+
|
205
|
+
Parameters:
|
206
|
+
level - minimal <Level>
|
207
|
+
*/
|
208
|
+
this.setLevel = function(level) {
|
209
|
+
if(!(level instanceof JLog.Level)) throw new Error("Logger.setLevel: please use JLog.Level to set Level");
|
210
|
+
// Having a level of null on the root logger would be very bad.
|
211
|
+
if(_isRoot && level === null)
|
212
|
+
throw new Error("Logger.setLevel: you cannot set the level of the root logger to null");
|
213
|
+
_currentLevel = level;
|
214
|
+
};
|
215
|
+
|
216
|
+
/*
|
217
|
+
Method: getLevel
|
218
|
+
|
219
|
+
Get minimal level of log messages to populate.
|
220
|
+
*/
|
221
|
+
this.getLevel = function() { return _currentLevel; };
|
222
|
+
|
223
|
+
this._getEffectiveLevel = function() {
|
224
|
+
for(var logger = this; logger !== null; logger = logger.parent) {
|
225
|
+
var level = logger.getLevel();
|
226
|
+
if(level !== null) return level;
|
227
|
+
}
|
228
|
+
};
|
229
|
+
|
230
|
+
this.toString = function() { return "Logger[" + this.getName() + "]"; };
|
231
|
+
};
|
232
|
+
|
233
|
+
Logger.prototype = {
|
234
|
+
/*
|
235
|
+
Method: debug
|
236
|
+
|
237
|
+
Attempt to publish <Level.DEBUG> message.
|
238
|
+
*/
|
239
|
+
debug: function() {
|
240
|
+
this.log(JLog.Level.DEBUG, arguments);
|
241
|
+
},
|
242
|
+
|
243
|
+
/*
|
244
|
+
Method: info
|
245
|
+
|
246
|
+
Attempt to publish <Level.INFO> message.
|
247
|
+
*/
|
248
|
+
info: function() {
|
249
|
+
this.log(JLog.Level.INFO, arguments);
|
250
|
+
},
|
251
|
+
|
252
|
+
/*
|
253
|
+
Method: warn
|
254
|
+
|
255
|
+
Attempt to publish <Level.WARN> message.
|
256
|
+
*/
|
257
|
+
warn: function() {
|
258
|
+
this.log(JLog.Level.WARN, arguments);
|
259
|
+
},
|
260
|
+
|
261
|
+
/*
|
262
|
+
Method: error
|
263
|
+
|
264
|
+
Attempt to publish <Level.ERROR> message.
|
265
|
+
*/
|
266
|
+
error: function() {
|
267
|
+
this.log(JLog.Level.ERROR, arguments);
|
268
|
+
},
|
269
|
+
|
270
|
+
/*
|
271
|
+
Method: fatal
|
272
|
+
|
273
|
+
Attempt to publish <Level.FATAL> message.
|
274
|
+
*/
|
275
|
+
fatal: function() {
|
276
|
+
this.log(JLog.Level.FATAL, arguments);
|
277
|
+
},
|
278
|
+
|
279
|
+
/*
|
280
|
+
Method: isEnabledFor
|
281
|
+
|
282
|
+
Checks if logger will publish message of given <Level>.
|
283
|
+
*/
|
284
|
+
isEnabledFor: function(level) {
|
285
|
+
return level >= this._getEffectiveLevel();
|
286
|
+
},
|
287
|
+
|
288
|
+
/*
|
289
|
+
Method: isDebugEnabled
|
290
|
+
|
291
|
+
Checks if logger will publish message of <Level.DEBUG>.
|
292
|
+
*/
|
293
|
+
isDebugEnabled: function() {
|
294
|
+
return this.isEnabledFor(JLog.Level.DEBUG);
|
295
|
+
},
|
296
|
+
|
297
|
+
/*
|
298
|
+
Method: isInfoEnabled
|
299
|
+
|
300
|
+
Checks if logger will publish message of <Level.INFO>.
|
301
|
+
*/
|
302
|
+
isInfoEnabled: function() {
|
303
|
+
return this.isEnabledFor(JLog.Level.INFO);
|
304
|
+
},
|
305
|
+
|
306
|
+
/*
|
307
|
+
Method: isWarnEnabled
|
308
|
+
|
309
|
+
Checks if logger will publish message of <Level.WARN>.
|
310
|
+
*/
|
311
|
+
isWarnEnabled: function() {
|
312
|
+
return this.isEnabledFor(JLog.Level.WARN);
|
313
|
+
},
|
314
|
+
|
315
|
+
/*
|
316
|
+
Method: isErrorEnabled
|
317
|
+
|
318
|
+
Checks if logger will publish message of <Level.ERROR>.
|
319
|
+
*/
|
320
|
+
isErrorEnabled: function() {
|
321
|
+
return this.isEnabledFor(JLog.Level.ERROR);
|
322
|
+
},
|
323
|
+
|
324
|
+
/*
|
325
|
+
Method: isFatalEnabled
|
326
|
+
|
327
|
+
Checks if logger will publish message of <Level.FATAL>.
|
328
|
+
*/
|
329
|
+
isFatalEnabled: function() {
|
330
|
+
return this.isEnabledFor(JLog.Level.FATAL);
|
331
|
+
}
|
332
|
+
};
|
333
|
+
|
334
|
+
/*
|
335
|
+
Method: getLogger
|
336
|
+
|
337
|
+
Returns instance of logger for given hierarchy.
|
338
|
+
|
339
|
+
Parameters:
|
340
|
+
loggerName - dot separated logger name.
|
341
|
+
|
342
|
+
Returns:
|
343
|
+
<Logger> for given name.
|
344
|
+
*/
|
345
|
+
JLog.getLogger = function(loggerName) {
|
346
|
+
// Use anonymous logger if loggerName is not specified or invalid
|
347
|
+
if (!(typeof loggerName == "string")) loggerName = anonymousLoggerName;
|
348
|
+
|
349
|
+
// Do not allow retrieval of the root logger by name
|
350
|
+
if (loggerName == rootLoggerName)
|
351
|
+
throw new Error("JLog.getLogger: root logger may not be obtained by name");
|
352
|
+
|
353
|
+
// Create the logger for this name if it doesn't already exist
|
354
|
+
if (!loggers[loggerName]) {
|
355
|
+
var logger = new Logger(loggerName);
|
356
|
+
loggers[loggerName] = logger;
|
357
|
+
loggerNames.push(loggerName);
|
358
|
+
|
359
|
+
// Set up parent logger, if it doesn't exist
|
360
|
+
var lastDotIndex = loggerName.lastIndexOf(".");
|
361
|
+
var parentLogger;
|
362
|
+
if(lastDotIndex > -1) {
|
363
|
+
var parentLoggerName = loggerName.substring(0, lastDotIndex);
|
364
|
+
parentLogger = JLog.getLogger(parentLoggerName); // Recursively sets up parents etc.
|
365
|
+
} else parentLogger = rootLogger;
|
366
|
+
parentLogger.addChild(logger);
|
367
|
+
}
|
368
|
+
return loggers[loggerName];
|
369
|
+
};
|
370
|
+
})(JLog);
|
@@ -0,0 +1,81 @@
|
|
1
|
+
/*
|
2
|
+
Class: LoggingEvent
|
3
|
+
|
4
|
+
Contains all the data about single log event.
|
5
|
+
*/
|
6
|
+
|
7
|
+
/*
|
8
|
+
Constructor: LoggingEvent
|
9
|
+
|
10
|
+
Initializes event.
|
11
|
+
|
12
|
+
Parameters:
|
13
|
+
logger - <Logger> which was the event source
|
14
|
+
timeStamp - Date of event occurrence
|
15
|
+
level - <Level> of the log event
|
16
|
+
messages - Array of messages in event
|
17
|
+
exception - Exception of the message
|
18
|
+
*/
|
19
|
+
JLog.LoggingEvent = function(logger, timeStamp, level, messages, exception) {
|
20
|
+
this.logger = logger;
|
21
|
+
this.timeStamp = timeStamp;
|
22
|
+
this.timeStampInMilliseconds = timeStamp.getTime();
|
23
|
+
this.timeStampInSeconds = Math.floor(this.timeStampInMilliseconds / 1000);
|
24
|
+
this.milliseconds = this.timeStamp.getMilliseconds();
|
25
|
+
this.level = level;
|
26
|
+
this.messages = messages;
|
27
|
+
this.exception = exception;
|
28
|
+
};
|
29
|
+
|
30
|
+
/*
|
31
|
+
Property: logger
|
32
|
+
|
33
|
+
<Logger> which was the event source
|
34
|
+
*/
|
35
|
+
|
36
|
+
/*
|
37
|
+
Property: timeStamp
|
38
|
+
|
39
|
+
Date of event occurrence
|
40
|
+
*/
|
41
|
+
|
42
|
+
/*
|
43
|
+
Property: level
|
44
|
+
|
45
|
+
<Level> of the log event
|
46
|
+
*/
|
47
|
+
|
48
|
+
/*
|
49
|
+
Property: messages
|
50
|
+
|
51
|
+
Array of messages in event
|
52
|
+
*/
|
53
|
+
|
54
|
+
/*
|
55
|
+
Property: exception
|
56
|
+
|
57
|
+
Exception of the message
|
58
|
+
*/
|
59
|
+
|
60
|
+
JLog.LoggingEvent.prototype = {
|
61
|
+
/*
|
62
|
+
Method: getThrowableStrRep
|
63
|
+
|
64
|
+
Returns exception of the message as a String.
|
65
|
+
*/
|
66
|
+
getThrowableStrRep: function() {
|
67
|
+
return this.exception ? getExceptionStringRep(this.exception) : "";
|
68
|
+
},
|
69
|
+
|
70
|
+
/*
|
71
|
+
Method: getCombinedMessages
|
72
|
+
|
73
|
+
Returns messages of the event joined with new line symbol.
|
74
|
+
*/
|
75
|
+
getCombinedMessages: function() {
|
76
|
+
return (this.messages.length == 1) ? this.messages[0] : this.messages.join(newLine);
|
77
|
+
},
|
78
|
+
toString: function() {
|
79
|
+
return "LoggingEvent[" + this.level + "]";
|
80
|
+
}
|
81
|
+
};
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jlog-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Helios Technologies
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jquery-rails
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ! '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: just_underscore
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
description: A lightweight JavaScript logger (for Rails)
|
28
42
|
email: contact@heliostech.fr
|
29
43
|
executables: []
|
@@ -46,7 +60,22 @@ files:
|
|
46
60
|
- lib/jlog/formatters.rb
|
47
61
|
- lib/jlog/version.rb
|
48
62
|
- script/rails
|
63
|
+
- test/ajax-appender-test.js
|
64
|
+
- test/buster.js
|
65
|
+
- test/lib/jquery-1.9.1.min.js
|
66
|
+
- test/lib/underscore.js
|
67
|
+
- test/logger-test.js
|
68
|
+
- test/pattern-layout-test.js
|
69
|
+
- vendor/assets/javascripts/appender.js
|
70
|
+
- vendor/assets/javascripts/appenders/ajax.js
|
71
|
+
- vendor/assets/javascripts/appenders/console.js
|
49
72
|
- vendor/assets/javascripts/jlog.js
|
73
|
+
- vendor/assets/javascripts/layout.js
|
74
|
+
- vendor/assets/javascripts/layouts/pattern.js
|
75
|
+
- vendor/assets/javascripts/levels.js
|
76
|
+
- vendor/assets/javascripts/logger.js
|
77
|
+
- vendor/assets/javascripts/logging_event.js
|
78
|
+
- vendor/assets/javascripts/mount.js
|
50
79
|
homepage: http://rubygems.org/gems/jlog-rails
|
51
80
|
licenses: []
|
52
81
|
metadata: {}
|
@@ -70,4 +99,10 @@ rubygems_version: 2.0.3
|
|
70
99
|
signing_key:
|
71
100
|
specification_version: 4
|
72
101
|
summary: Jlog for Rails
|
73
|
-
test_files:
|
102
|
+
test_files:
|
103
|
+
- test/ajax-appender-test.js
|
104
|
+
- test/buster.js
|
105
|
+
- test/lib/jquery-1.9.1.min.js
|
106
|
+
- test/lib/underscore.js
|
107
|
+
- test/logger-test.js
|
108
|
+
- test/pattern-layout-test.js
|