1 |
efrain |
1 |
YUI.add('yui-log', function (Y, NAME) {
|
|
|
2 |
|
|
|
3 |
/**
|
|
|
4 |
* Provides console log capability and exposes a custom event for
|
|
|
5 |
* console implementations. This module is a `core` YUI module,
|
|
|
6 |
* <a href="../classes/YUI.html#method_log">it's documentation is located under the YUI class</a>.
|
|
|
7 |
*
|
|
|
8 |
* @module yui
|
|
|
9 |
* @submodule yui-log
|
|
|
10 |
*/
|
|
|
11 |
|
|
|
12 |
var INSTANCE = Y,
|
|
|
13 |
LOGEVENT = 'yui:log',
|
|
|
14 |
UNDEFINED = 'undefined',
|
|
|
15 |
LEVELS = { debug: 1,
|
|
|
16 |
info: 2,
|
|
|
17 |
warn: 4,
|
|
|
18 |
error: 8 };
|
|
|
19 |
|
|
|
20 |
/**
|
|
|
21 |
* If the 'debug' config is true, a 'yui:log' event will be
|
|
|
22 |
* dispatched, which the Console widget and anything else
|
|
|
23 |
* can consume. If the 'useBrowserConsole' config is true, it will
|
|
|
24 |
* write to the browser console if available. YUI-specific log
|
|
|
25 |
* messages will only be present in the -debug versions of the
|
|
|
26 |
* JS files. The build system is supposed to remove log statements
|
|
|
27 |
* from the raw and minified versions of the files.
|
|
|
28 |
*
|
|
|
29 |
* @method log
|
|
|
30 |
* @for YUI
|
|
|
31 |
* @param {String} msg The message to log.
|
|
|
32 |
* @param {String} cat The log category for the message. Default
|
|
|
33 |
* categories are "info", "warn", "error", "debug".
|
|
|
34 |
* Custom categories can be used as well. (opt).
|
|
|
35 |
* @param {String} src The source of the the message (opt).
|
|
|
36 |
* @param {boolean} silent If true, the log event won't fire.
|
|
|
37 |
* @return {YUI} YUI instance.
|
|
|
38 |
*/
|
|
|
39 |
INSTANCE.log = function(msg, cat, src, silent) {
|
|
|
40 |
var bail, excl, incl, m, f, minlevel,
|
|
|
41 |
Y = INSTANCE,
|
|
|
42 |
c = Y.config,
|
|
|
43 |
publisher = (Y.fire) ? Y : YUI.Env.globalEvents;
|
|
|
44 |
// suppress log message if the config is off or the event stack
|
|
|
45 |
// or the event call stack contains a consumer of the yui:log event
|
|
|
46 |
if (c.debug) {
|
|
|
47 |
// apply source filters
|
|
|
48 |
src = src || "";
|
|
|
49 |
if (typeof src !== "undefined") {
|
|
|
50 |
excl = c.logExclude;
|
|
|
51 |
incl = c.logInclude;
|
|
|
52 |
if (incl && !(src in incl)) {
|
|
|
53 |
bail = 1;
|
|
|
54 |
} else if (incl && (src in incl)) {
|
|
|
55 |
bail = !incl[src];
|
|
|
56 |
} else if (excl && (src in excl)) {
|
|
|
57 |
bail = excl[src];
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
// Set a default category of info if the category was not defined.
|
|
|
61 |
if ((typeof cat === 'undefined')) {
|
|
|
62 |
cat = 'info';
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
// Determine the current minlevel as defined in configuration
|
|
|
66 |
Y.config.logLevel = Y.config.logLevel || 'debug';
|
|
|
67 |
minlevel = LEVELS[Y.config.logLevel.toLowerCase()];
|
|
|
68 |
|
|
|
69 |
if (cat in LEVELS && LEVELS[cat] < minlevel) {
|
|
|
70 |
// Skip this message if the we don't meet the defined minlevel
|
|
|
71 |
bail = 1;
|
|
|
72 |
}
|
|
|
73 |
}
|
|
|
74 |
if (!bail) {
|
|
|
75 |
if (c.useBrowserConsole) {
|
|
|
76 |
m = (src) ? src + ': ' + msg : msg;
|
|
|
77 |
if (Y.Lang.isFunction(c.logFn)) {
|
|
|
78 |
c.logFn.call(Y, msg, cat, src);
|
|
|
79 |
} else if (typeof console !== UNDEFINED && console.log) {
|
|
|
80 |
f = (cat && console[cat] && (cat in LEVELS)) ? cat : 'log';
|
|
|
81 |
console[f](m);
|
|
|
82 |
} else if (typeof opera !== UNDEFINED) {
|
|
|
83 |
opera.postError(m);
|
|
|
84 |
}
|
|
|
85 |
}
|
|
|
86 |
|
|
|
87 |
if (publisher && !silent) {
|
|
|
88 |
|
|
|
89 |
if (publisher === Y && (!publisher.getEvent(LOGEVENT))) {
|
|
|
90 |
publisher.publish(LOGEVENT, {
|
|
|
91 |
broadcast: 2
|
|
|
92 |
});
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
publisher.fire(LOGEVENT, {
|
|
|
96 |
msg: msg,
|
|
|
97 |
cat: cat,
|
|
|
98 |
src: src
|
|
|
99 |
});
|
|
|
100 |
}
|
|
|
101 |
}
|
|
|
102 |
}
|
|
|
103 |
|
|
|
104 |
return Y;
|
|
|
105 |
};
|
|
|
106 |
|
|
|
107 |
/**
|
|
|
108 |
* Write a system message. This message will be preserved in the
|
|
|
109 |
* minified and raw versions of the YUI files, unlike log statements.
|
|
|
110 |
* @method message
|
|
|
111 |
* @for YUI
|
|
|
112 |
* @param {String} msg The message to log.
|
|
|
113 |
* @param {String} cat The log category for the message. Default
|
|
|
114 |
* categories are "info", "warn", "error", "debug".
|
|
|
115 |
* Custom categories can be used as well. (opt).
|
|
|
116 |
* @param {String} src The source of the the message (opt).
|
|
|
117 |
* @param {boolean} silent If true, the log event won't fire.
|
|
|
118 |
* @return {YUI} YUI instance.
|
|
|
119 |
*/
|
|
|
120 |
INSTANCE.message = function() {
|
|
|
121 |
return INSTANCE.log.apply(INSTANCE, arguments);
|
|
|
122 |
};
|
|
|
123 |
|
|
|
124 |
|
|
|
125 |
}, '3.18.1', {"requires": ["yui-base"]});
|