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