yui-log-debug.js revision ea1a3ebe8a45a2dd13c9916712a770af77f7443b
17816N/AYUI.add('yui-log', function(Y) {
17816N/A
17816N/A/**
17816N/A * Provides console log capability and exposes a custom event for
17816N/A * console implementations.
17816N/A * @module yui
17816N/A * @submodule yui-log
17816N/A */
17816N/A(function() {
17816N/A
17816N/Avar INSTANCE = Y,
17816N/A LOGEVENT = 'yui:log',
17816N/A UNDEFINED = 'undefined',
17816N/A LEVELS = { debug: 1, info: 1, warn: 1, error: 1 },
17816N/A _published;
17816N/A
17816N/A/**
17816N/A * If the 'debug' config is true, a 'yui:log' event will be
17816N/A * dispatched, which the Console widget and anything else
17816N/A * can consume. If the 'useBrowserConsole' config is true, it will
17816N/A * write to the browser console if available. YUI-specific log
17816N/A * messages will only be present in the -debug versions of the
17816N/A * JS files. The build system is supposed to remove log statements
17816N/A * from the raw and minified versions of the files.
17816N/A *
17816N/A * @method log
17816N/A * @for YUI
17816N/A * @param {String} msg The message to log.
17816N/A * @param {String} cat The log category for the message. Default
17816N/A * categories are "info", "warn", "error", time".
17816N/A * Custom categories can be used as well. (opt)
17816N/A * @param {String} src The source of the the message (opt)
17816N/A * @param {boolean} silent If true, the log event won't fire
17816N/A * @return {YUI} YUI instance
17816N/A */
17816N/AINSTANCE.log = function(msg, cat, src, silent) {
17816N/A var Y = INSTANCE, c = Y.config, bail = false, excl, incl, m, f;
17816N/A // suppress log message if the config is off or the event stack
17816N/A // or the event call stack contains a consumer of the yui:log event
17816N/A if (c.debug) {
17816N/A // apply source filters
17816N/A if (src) {
17816N/A excl = c.logExclude;
17816N/A incl = c.logInclude;
17816N/A
17816N/A if (incl && !(src in incl)) {
17816N/A bail = 1;
17816N/A } else if (excl && (src in excl)) {
17816N/A bail = 1;
17816N/A }
17816N/A }
17816N/A
17816N/A if (!bail) {
if (c.useBrowserConsole) {
m = (src) ? src + ': ' + msg : msg;
if (Y.Lang.isFunction(c.logFn)) {
c.logFn(msg, cat, src);
} if (typeof console != UNDEFINED && console.log) {
f = (cat && console[cat] && (cat in LEVELS)) ? cat : 'log';
console[f](m);
} else if (typeof opera != UNDEFINED) {
opera.postError(m);
}
}
if (Y.fire && !silent) {
if (!_published) {
Y.publish(LOGEVENT, {
broadcast: 2
});
_published = 1;
}
Y.fire(LOGEVENT, {
msg: msg,
cat: cat,
src: src
});
}
}
}
return Y;
};
/**
* Write a system message. This message will be preserved in the
* minified and raw versions of the YUI files, unlike log statements.
* @method message
* @for YUI
* @param {String} msg The message to log.
* @param {String} cat The log category for the message. Default
* categories are "info", "warn", "error", time".
* Custom categories can be used as well. (opt)
* @param {String} src The source of the the message (opt)
* @param {boolean} silent If true, the log event won't fire
* @return {YUI} YUI instance
*/
INSTANCE.message = function() {
return INSTANCE.log.apply(INSTANCE, arguments);
};
})();
}, '@VERSION@' ,{requires:['yui-base']});