forked from mamonth/yam-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Logger.js
104 lines (80 loc) · 2.87 KB
/
Logger.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/**
* App Logger module
*
* @author Max Maximov <[email protected]>
* @version 0.2.1
*/
define("app/Logger", function () {
"use strict";
$.Class.extend("app.Logger",
/* @static */
{
NONE: 0,
ERROR: 1,
WARN: 2,
INFO: 3,
DEBUG: 4,
LOG: 5,
level: 1,
ie: ( $.browser.msie !== undefined ) ? $.browser.msie : false,
init: function() {
window["_console"] = typeof console != "undefined" ?
console :
{
log:function() {},
debug:function() {},
info:function() {},
warn:function() {},
error:function() {}
};
// Crunch in case direct console use
if( window.console === undefined ) {
window.console = {
log:function() {},
debug:function() {},
info:function() {},
warn:function() {},
error:function() {}
};
}
},
_parseArgs: function () {
var args = Array.prototype.slice.call(arguments[0]);
// Тут бы, по-хорошему, интерфейс нужен, вместо typeof args[0] == "object"
return ([typeof args[0] == "object" ? "[" + args[0].constructor.fullName + "]" : args[0]].concat(args.slice(1)));
},
_echo: function (args, type) {
var args = app.Logger._parseArgs(args);
/* @cc_on app.Logger.ie = true; @ */
if (app.Logger.debug && window.console && window.console[type]) {
if (app.Logger.ie) {
console[type](args.join(" "));
} else {
console[type].apply(console, args);
}
}
},
log: function () {
if (app.Logger.level >= app.Logger.LOG) app.Logger._echo(arguments, "log");
},
tLog: function () {
if ( (app.Logger.level >= app.Logger.LOG || app.Logger.timing) && navigator.userAgent.indexOf('MSIE') ==-1 ) console["log"].apply(console, app.Logger._parseArgs(arguments));//app.Logger._echo(arguments, "log");
},
debug: function () {
if (app.Logger.level >= app.Logger.DEBUG) app.Logger._echo(arguments, "debug");
},
info: function () {
if (app.Logger.level >= app.Logger.INFO) app.Logger._echo(arguments, "info");
},
warn: function () {
if (app.Logger.level >= app.Logger.WARN) app.Logger._echo(arguments, "warn");
},
error: function () {
if (app.Logger.level >= app.Logger.ERROR) app.Logger._echo(arguments, "error");
}
},
/* @prototype */
{
});
return app.Logger;
});