jlog-rails 0.1.0 → 0.1.1
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 +6 -0
- data/lib/jlog/version.rb +1 -1
- data/vendor/assets/javascripts/jlog.js +118 -115
- metadata +1 -1
data/README.md
CHANGED
@@ -23,6 +23,12 @@ On the client-side:
|
|
23
23
|
Changelog:
|
24
24
|
----------
|
25
25
|
|
26
|
+
* 0.1.1
|
27
|
+
* Cleaned JLog.JS code
|
28
|
+
* 0.1.0
|
29
|
+
* JLog rails engine can now be mounted several times
|
30
|
+
* Added ability to configure the ruby logger(s) and the output format(s)
|
31
|
+
* Fixed JSHint warnings
|
26
32
|
* 0.0.3
|
27
33
|
* Adding bulk flush in the ajax appender
|
28
34
|
* 0.0.2
|
data/lib/jlog/version.rb
CHANGED
@@ -26,155 +26,158 @@
|
|
26
26
|
|
27
27
|
/**
|
28
28
|
*
|
29
|
-
* @remixer Helios Technologies
|
29
|
+
* @remixer Helios Technologies mailto:contact@heliostech.fr
|
30
30
|
*
|
31
31
|
**/
|
32
32
|
|
33
33
|
function JLog(name) {
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
_enabled = true;
|
34
|
+
this._appenders.push(new JLog.ConsoleAppender());
|
35
|
+
this.setName(name);
|
36
|
+
}
|
38
37
|
|
39
|
-
|
40
|
-
|
41
|
-
|
38
|
+
JLog.ALL = 0;
|
39
|
+
JLog.DEBUG = 1;
|
40
|
+
JLog.INFO = 2;
|
41
|
+
JLog.WARN = 3;
|
42
|
+
JLog.ERROR = 4;
|
43
|
+
JLog.FATAL = 5;
|
44
|
+
JLog.NONE = 6;
|
45
|
+
|
46
|
+
JLog.prototype = {
|
47
|
+
_currentLevel: JLog.ALL,
|
48
|
+
_appenders: [],
|
49
|
+
_enabled: true,
|
50
|
+
_name: null,
|
51
|
+
|
52
|
+
debug: function() {
|
53
|
+
if (this.getLevel() <= JLog.DEBUG) {
|
54
|
+
this._log("DEBUG", arguments);
|
55
|
+
}
|
56
|
+
},
|
42
57
|
|
43
|
-
|
44
|
-
this.
|
45
|
-
|
58
|
+
info: function() {
|
59
|
+
if (this.getLevel() <= JLog.INFO) {
|
60
|
+
this._log("INFO", arguments);
|
61
|
+
}
|
62
|
+
},
|
63
|
+
|
64
|
+
warn: function() {
|
65
|
+
if (this.getLevel() <= JLog.WARN) {
|
66
|
+
this._log("WARN", arguments);
|
67
|
+
}
|
68
|
+
},
|
46
69
|
|
47
|
-
|
70
|
+
error: function() {
|
71
|
+
if (this.getLevel() <= JLog.ERROR) {
|
72
|
+
this._log("ERROR", arguments);
|
73
|
+
}
|
74
|
+
},
|
75
|
+
|
76
|
+
fatal: function() {
|
77
|
+
if (this.getLevel() <= JLog.FATAL) {
|
78
|
+
this._log("FATAL", arguments);
|
79
|
+
}
|
80
|
+
},
|
81
|
+
|
82
|
+
_log: function() {
|
83
|
+
if (this.isOn()) {
|
84
|
+
var level = arguments[0],
|
85
|
+
args = Array.prototype.slice.call(arguments[1] || []),
|
86
|
+
namePrefix = this.getName() ? '[' + this.getName() + ']' : '',
|
87
|
+
msgString = level + namePrefix + ': ',
|
88
|
+
appenders = this.getAppenders();
|
89
|
+
|
90
|
+
for (var i in args) {
|
91
|
+
if (typeof args[i] === 'object') {
|
92
|
+
args[i] = JSON.stringify(args[i]);
|
93
|
+
}
|
94
|
+
}
|
95
|
+
|
96
|
+
msgString += args.join(', ');
|
97
|
+
for(i = 0; i < appenders.length; ++i) {
|
98
|
+
appenders[i].log(msgString);
|
99
|
+
}
|
100
|
+
}
|
101
|
+
},
|
102
|
+
|
103
|
+
getName: function() {
|
104
|
+
return _name;
|
105
|
+
},
|
106
|
+
|
107
|
+
setName: function(name) {
|
108
|
+
_name = name || null;
|
109
|
+
},
|
110
|
+
|
111
|
+
addAppender: function(appender) {
|
48
112
|
if (appender) {
|
49
|
-
_appenders.push(appender);
|
113
|
+
this._appenders.push(appender);
|
50
114
|
}
|
51
|
-
}
|
115
|
+
},
|
52
116
|
|
53
|
-
|
117
|
+
removeAppender: function(name) {
|
54
118
|
for (var i in _appenders) {
|
55
|
-
if (_appenders[i].name === name) {
|
56
|
-
_appenders.splice(i, 1);
|
119
|
+
if (this._appenders[i].name === name) {
|
120
|
+
this._appenders.splice(i, 1);
|
57
121
|
}
|
58
122
|
}
|
59
123
|
return null;
|
60
|
-
}
|
124
|
+
},
|
61
125
|
|
62
|
-
|
63
|
-
_enabled = true;
|
64
|
-
}
|
126
|
+
turnOn: function() {
|
127
|
+
this._enabled = true;
|
128
|
+
},
|
65
129
|
|
66
|
-
|
67
|
-
_enabled = false;
|
68
|
-
}
|
130
|
+
turnOff: function() {
|
131
|
+
this._enabled = false;
|
132
|
+
},
|
69
133
|
|
70
|
-
|
71
|
-
return _enabled;
|
72
|
-
}
|
134
|
+
isOn: function() {
|
135
|
+
return this._enabled;
|
136
|
+
},
|
73
137
|
|
74
|
-
//
|
75
|
-
|
138
|
+
//
|
139
|
+
// Sets the current threshold log level for this Log instance.
|
140
|
+
// Only events that have a priority of this level or greater are logged.
|
141
|
+
//
|
142
|
+
setLevel: function(level) {
|
76
143
|
if (typeof level === 'number') {
|
77
144
|
if (level >= JLog.ALL && level <= JLog.NONE) {
|
78
|
-
_currentLevel = level;
|
145
|
+
this._currentLevel = level;
|
79
146
|
} else {
|
80
|
-
_currentLevel = JLog.NONE;
|
147
|
+
this._currentLevel = JLog.NONE;
|
81
148
|
}
|
82
149
|
} else if (level) {
|
83
150
|
switch(level) {
|
84
|
-
case 'all': _currentLevel = JLog.ALL; break;
|
85
|
-
case 'debug': _currentLevel = JLog.DEBUG; break;
|
86
|
-
case 'info': _currentLevel = JLog.INFO; break;
|
87
|
-
case 'warn': _currentLevel = JLog.WARN; break;
|
88
|
-
case 'error': _currentLevel = JLog.ERROR; break;
|
89
|
-
case 'fatal': _currentLevel = JLog.FATAL; break;
|
90
|
-
default: _currentLevel = JLog.NONE;
|
151
|
+
case 'all': this._currentLevel = JLog.ALL; break;
|
152
|
+
case 'debug': this._currentLevel = JLog.DEBUG; break;
|
153
|
+
case 'info': this._currentLevel = JLog.INFO; break;
|
154
|
+
case 'warn': this._currentLevel = JLog.WARN; break;
|
155
|
+
case 'error': this._currentLevel = JLog.ERROR; break;
|
156
|
+
case 'fatal': this._currentLevel = JLog.FATAL; break;
|
157
|
+
default: this._currentLevel = JLog.NONE;
|
91
158
|
}
|
92
159
|
} else {
|
93
|
-
_currentLevel = JLog.NONE;
|
160
|
+
this._currentLevel = JLog.NONE;
|
94
161
|
}
|
95
|
-
}
|
96
|
-
|
97
|
-
this.getName = function() {
|
98
|
-
return _name;
|
99
|
-
};
|
162
|
+
},
|
100
163
|
|
101
|
-
|
102
|
-
for (var i in _appenders) {
|
103
|
-
if (_appenders[i].name === name) {
|
104
|
-
return _appenders[i];
|
164
|
+
getAppender: function(name) {
|
165
|
+
for (var i in this._appenders) {
|
166
|
+
if (this._appenders[i].name === name) {
|
167
|
+
return this._appenders[i];
|
105
168
|
}
|
106
169
|
}
|
107
170
|
return null;
|
108
|
-
}
|
109
|
-
|
110
|
-
this.getAppenders = function() {
|
111
|
-
return _appenders;
|
112
|
-
};
|
113
|
-
|
114
|
-
this.getLevel = function() {
|
115
|
-
return _currentLevel;
|
116
|
-
};
|
117
|
-
}
|
118
|
-
|
119
|
-
JLog.ALL = 0;
|
120
|
-
JLog.DEBUG = 1;
|
121
|
-
JLog.INFO = 2;
|
122
|
-
JLog.WARN = 3;
|
123
|
-
JLog.ERROR = 4;
|
124
|
-
JLog.FATAL = 5;
|
125
|
-
JLog.NONE = 6;
|
171
|
+
},
|
126
172
|
|
173
|
+
getAppenders: function() {
|
174
|
+
return this._appenders;
|
175
|
+
},
|
127
176
|
|
128
|
-
|
129
|
-
|
130
|
-
this._log("DEBUG", arguments);
|
177
|
+
getLevel: function() {
|
178
|
+
return this._currentLevel;
|
131
179
|
}
|
132
|
-
}
|
133
|
-
|
134
|
-
JLog.prototype.info = function() {
|
135
|
-
if (this.getLevel() <= JLog.INFO) {
|
136
|
-
this._log("INFO", arguments);
|
137
|
-
}
|
138
|
-
};
|
139
|
-
|
140
|
-
JLog.prototype.warn = function() {
|
141
|
-
if (this.getLevel() <= JLog.WARN) {
|
142
|
-
this._log("WARN", arguments);
|
143
|
-
}
|
144
|
-
};
|
145
|
-
|
146
|
-
JLog.prototype.error = function() {
|
147
|
-
if (this.getLevel() <= JLog.ERROR) {
|
148
|
-
this._log("ERROR", arguments);
|
149
|
-
}
|
150
|
-
};
|
151
|
-
|
152
|
-
JLog.prototype.fatal = function() {
|
153
|
-
if (this.getLevel() <= JLog.FATAL) {
|
154
|
-
this._log("FATAL", arguments);
|
155
|
-
}
|
156
|
-
};
|
157
|
-
|
158
|
-
JLog.prototype._log = function() {
|
159
|
-
if (this.isOn()) {
|
160
|
-
var level = arguments[0],
|
161
|
-
args = Array.prototype.slice.call(arguments[1]),
|
162
|
-
namePrefix = this.getName() ? '[' + this.getName() + ']' : '',
|
163
|
-
msgString = level + namePrefix + ': ',
|
164
|
-
appenders = this.getAppenders();
|
165
|
-
|
166
|
-
for (var i in args) {
|
167
|
-
if (typeof args[i] === 'object') {
|
168
|
-
args[i] = JSON.stringify(args[i]);
|
169
|
-
}
|
170
|
-
}
|
171
|
-
|
172
|
-
msgString += args.join(', ');
|
173
|
-
for(i = 0; i < appenders.length; ++i) {
|
174
|
-
appenders[i].log(msgString);
|
175
|
-
}
|
176
|
-
}
|
177
|
-
};
|
180
|
+
}
|
178
181
|
|
179
182
|
JLog.ConsoleAppender = function() {
|
180
183
|
this.name = 'ConsoleAppender';
|