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