-
Notifications
You must be signed in to change notification settings - Fork 9
/
client.js
55 lines (48 loc) · 1.4 KB
/
client.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
(function (factory) {
if (typeof define === 'function' && define.amd) {
// Register as an AMD module if available...
define(['jquery'], factory);
} else {
// Browser globals for the unenlightened...
factory($);
}
}(function($){
"use strict";
var levels = {LEVELS:LEVELS};
var console = console;
var Winston = new Function();
Winston.log = function(level, message, meta) {
var url = '/winston/log/' + encodeURIComponent(level) +
'/' + encodeURIComponent(message);
if (meta) {
url += '/' + encodeURIComponent(JSON.stringify(meta));
}
// send it to the server
$.ajax({url: url});
// log it to the browser console
if (typeof console !== 'undefined') {
level = (console[level] ? level : 'log');
console[level](level + ': ' + message);
}
};
// attach methods for each log level
for (var level in levels) {
if (levels.hasOwnProperty(level)) {
(function(level) {
Winston[level] = function(message, cb) {
this.log(level, message, cb);
};
})(level);
}
}
if (typeof define === 'function' && define.amd) {
// Register as an AMD module if available...
return Winston
} else {
window.onerror = function(msg, url, code) {
var error = msg + " in " + url + " with code " + code;
winston.error(error);
};
window.winston = Winston;
}
}));