]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - jssource/src_files/include/javascript/yui3/build/yui/yui-log.js
Release 6.2.0beta4
[Github/sugarcrm.git] / jssource / src_files / include / javascript / yui3 / build / yui / yui-log.js
1 /*
2 Copyright (c) 2009, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.net/yui/license.txt
5 version: 3.0.0
6 build: 1549
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 (function() {
17
18 var INSTANCE = Y,
19     LOGEVENT = 'yui:log',
20     UNDEFINED = 'undefined',
21     LEVELS = { debug: 1, info: 1, warn: 1, error: 1 },
22     _published;
23
24 /**
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.
32  *
33  * @method log
34  * @for YUI
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
42  */
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
47     if (c.debug) {
48         // apply source filters
49         if (src) {
50             excl = c.logExclude; 
51             incl = c.logInclude;
52
53             if (incl && !(src in incl)) {
54                 bail = 1;
55             } else if (excl && (src in excl)) {
56                 bail = 1;
57             }
58         }
59
60         if (!bail) {
61
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';
66                     console[f](m);
67                 } else if (typeof opera != UNDEFINED) {
68                     opera.postError(m);
69                 }
70             }
71
72             if (Y.fire && !silent) {
73                 if (!_published) {
74                     Y.publish(LOGEVENT, {
75                         broadcast: 2,
76                         emitFacade: 1
77                     });
78
79                     _published = 1;
80
81                 }
82                 Y.fire(LOGEVENT, {
83                     msg: msg, 
84                     cat: cat, 
85                     src: src
86                 });
87             }
88         }
89     }
90
91     return Y;
92 };
93
94 /**
95  * Write a system message.  This message will be preserved in the
96  * minified and raw versions of the YUI files, unlike log statements.
97  * @method message
98  * @for YUI
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
106  */
107 INSTANCE.message = function() {
108     return INSTANCE.log.apply(INSTANCE, arguments);
109 };
110
111 })();
112
113
114 }, '3.0.0' ,{requires:['yui-base']});