]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - jssource/src_files/include/javascript/yui3/build/yui/yui-log.js
Release 6.5.0
[Github/sugarcrm.git] / jssource / src_files / include / javascript / yui3 / build / yui / yui-log.js
1 /*
2 Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.com/yui/license.html
5 version: 3.3.0
6 build: 3167
7 */
8 YUI.add('yui-log', function(Y) {
9
10 /**
11  * Provides console log capability and exposes a custom event for
12  * console implementations.
13  * @module yui
14  * @submodule yui-log
15  */
16
17 var INSTANCE = Y,
18     LOGEVENT = 'yui:log',
19     UNDEFINED = 'undefined',
20     LEVELS = { debug: 1,
21                info: 1,
22                warn: 1,
23                error: 1 };
24
25 /**
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.
33  *
34  * @method log
35  * @for YUI
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.
43  */
44 INSTANCE.log = function(msg, cat, src, silent) {
45     var bail, excl, incl, m, f,
46         Y = INSTANCE,
47         c = Y.config,
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
51     if (c.debug) {
52         // apply source filters
53         if (src) {
54             excl = c.logExclude;
55             incl = c.logInclude;
56             if (incl && !(src in incl)) {
57                 bail = 1;
58             } else if (excl && (src in excl)) {
59                 bail = 1;
60             }
61         }
62         if (!bail) {
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';
69                     console[f](m);
70                 } else if (typeof opera != UNDEFINED) {
71                     opera.postError(m);
72                 }
73             }
74
75             if (publisher && !silent) {
76
77                 if (publisher == Y && (!publisher.getEvent(LOGEVENT))) {
78                     publisher.publish(LOGEVENT, {
79                         broadcast: 2
80                     });
81                 }
82
83                 publisher.fire(LOGEVENT, {
84                     msg: msg,
85                     cat: cat,
86                     src: src
87                 });
88             }
89         }
90     }
91
92     return Y;
93 };
94
95 /**
96  * Write a system message.  This message will be preserved in the
97  * minified and raw versions of the YUI files, unlike log statements.
98  * @method message
99  * @for YUI
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.
107  */
108 INSTANCE.message = function() {
109     return INSTANCE.log.apply(INSTANCE, arguments);
110 };
111
112
113 }, '3.3.0' ,{requires:['yui-base']});