2 Copyright (c) 2009, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.net/yui/license.txt
8 YUI.add('yui-log', function(Y) {
11 * Provides console log capability and exposes a custom event for
12 * console implementations.
20 UNDEFINED = 'undefined',
21 LEVELS = { debug: 1, info: 1, warn: 1, error: 1 },
25 * If the 'debug' config is true, a 'yui:log' event will be
26 * dispatched, which the Console widget and anything else
27 * can consume. If the 'useBrowserConsole' config is true, it will
28 * write to the browser console if available. YUI-specific log
29 * messages will only be present in the -debug versions of the
30 * JS files. The build system is supposed to remove log statements
31 * from the raw and minified versions of the files.
35 * @param {String} msg The message to log.
36 * @param {String} cat The log category for the message. Default
37 * categories are "info", "warn", "error", time".
38 * Custom categories can be used as well. (opt)
39 * @param {String} src The source of the the message (opt)
40 * @param {boolean} silent If true, the log event won't fire
41 * @return {YUI} YUI instance
43 INSTANCE.log = function(msg, cat, src, silent) {
44 var Y = INSTANCE, c = Y.config, bail = false, excl, incl, m, f;
45 // suppress log message if the config is off or the event stack
46 // or the event call stack contains a consumer of the yui:log event
48 // apply source filters
53 if (incl && !(src in incl)) {
55 } else if (excl && (src in excl)) {
62 if (c.useBrowserConsole) {
63 m = (src) ? src + ': ' + msg : msg;
64 if (typeof console != UNDEFINED && console.log) {
65 f = (cat && console[cat] && (cat in LEVELS)) ? cat : 'log';
67 } else if (typeof opera != UNDEFINED) {
72 if (Y.fire && !silent) {
95 * Write a system message. This message will be preserved in the
96 * minified and raw versions of the YUI files, unlike log statements.
99 * @param {String} msg The message to log.
100 * @param {String} cat The log category for the message. Default
101 * categories are "info", "warn", "error", time".
102 * Custom categories can be used as well. (opt)
103 * @param {String} src The source of the the message (opt)
104 * @param {boolean} silent If true, the log event won't fire
105 * @return {YUI} YUI instance
107 INSTANCE.message = function() {
108 return INSTANCE.log.apply(INSTANCE, arguments);
114 }, '3.0.0' ,{requires:['yui-base']});