2 Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.com/yui/license.html
8 YUI.add('yui-log', function(Y) {
11 * Provides console log capability and exposes a custom event for
12 * console implementations.
19 UNDEFINED = 'undefined',
26 * If the 'debug' config is true, a 'yui:log' event will be
27 * dispatched, which the Console widget and anything else
28 * can consume. If the 'useBrowserConsole' config is true, it will
29 * write to the browser console if available. YUI-specific log
30 * messages will only be present in the -debug versions of the
31 * JS files. The build system is supposed to remove log statements
32 * from the raw and minified versions of the files.
36 * @param {String} msg The message to log.
37 * @param {String} cat The log category for the message. Default
38 * categories are "info", "warn", "error", time".
39 * Custom categories can be used as well. (opt).
40 * @param {String} src The source of the the message (opt).
41 * @param {boolean} silent If true, the log event won't fire.
42 * @return {YUI} YUI instance.
44 INSTANCE.log = function(msg, cat, src, silent) {
45 var bail, excl, incl, m, f,
48 publisher = (Y.fire) ? Y : YUI.Env.globalEvents;
49 // suppress log message if the config is off or the event stack
50 // or the event call stack contains a consumer of the yui:log event
52 // apply source filters
56 if (incl && !(src in incl)) {
58 } else if (excl && (src in excl)) {
63 if (c.useBrowserConsole) {
64 m = (src) ? src + ': ' + msg : msg;
65 if (Y.Lang.isFunction(c.logFn)) {
66 c.logFn.call(Y, msg, cat, src);
67 } else if (typeof console != UNDEFINED && console.log) {
68 f = (cat && console[cat] && (cat in LEVELS)) ? cat : 'log';
70 } else if (typeof opera != UNDEFINED) {
75 if (publisher && !silent) {
77 if (publisher == Y && (!publisher.getEvent(LOGEVENT))) {
78 publisher.publish(LOGEVENT, {
83 publisher.fire(LOGEVENT, {
96 * Write a system message. This message will be preserved in the
97 * minified and raw versions of the YUI files, unlike log statements.
100 * @param {String} msg The message to log.
101 * @param {String} cat The log category for the message. Default
102 * categories are "info", "warn", "error", time".
103 * Custom categories can be used as well. (opt).
104 * @param {String} src The source of the the message (opt).
105 * @param {boolean} silent If true, the log event won't fire.
106 * @return {YUI} YUI instance.
108 INSTANCE.message = function() {
109 return INSTANCE.log.apply(INSTANCE, arguments);
113 }, '3.3.0' ,{requires:['yui-base']});