yui-log.js.html revision eb9b6f817df5c660be9f00fc5d27fe33479fdc98
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>API: yui yui-log.js (YUI Library)</title>
<link rel="stylesheet" type="text/css" href="assets/api.css">
<script type="text/javascript" src="assets/api-js"></script>
<script type="text/javascript" src="assets/ac-js"></script>
</head>
<body id="yahoo-com">
<div id="doc3" class="yui-t2">
<div id="hd">
<a href="http://developer.yahoo.com/yui/"><h1>Yahoo! UI Library</h1></a>
<h3>yui&nbsp; <span class="subtitle">3.00PR1</span></h3>
<p>
<a href="/index.html">Yahoo! UI Library</a>
&gt; <a href="/module_yui.html">yui</a>
&gt; yui-log.js (source view)
</p>
</div>
<div id="bd">
<div id="yui-main">
<div class="yui-b">
<form name="yui-classopts-form">
<span id="classopts"><input type="checkbox" name="showprivate" id="showprivate" /> Show Private</span>
<span id="classopts"><input type="checkbox" name="showprotected" id="showprotected" /> Show Protected</span>
<span id="classopts"><input type="checkbox" name="showdeprecated" id="showdeprecated" /> Show Deprecated</span>
</form>
<div id="srcout">
<style>
#doc3 #classopts { display:none; }
</style>
<div class="highlight" ><pre><span class="nx">YUI</span><span class="o">.</span><span class="nx">add</span><span class="o">(</span><span class="s2">&quot;log&quot;</span><span class="o">,</span> <span class="k">function</span><span class="o">(</span><span class="nx">instance</span><span class="o">)</span> <span class="o">{</span>
<span class="c">/**</span>
<span class="c"> * If the &#39;debug&#39; config is true, a &#39;yui:log&#39; event will be</span>
<span class="c"> * dispatched, which the logger widget and anything else</span>
<span class="c"> * can consume. If the &#39;useConsole&#39; config is true, it will</span>
<span class="c"> * write to the browser console if available.</span>
<span class="c"> *</span>
<span class="c"> * @method log</span>
<span class="c"> * @for YUI</span>
<span class="c"> * @param {String} msg The message to log.</span>
<span class="c"> * @param {String} cat The log category for the message. Default</span>
<span class="c"> * categories are &quot;info&quot;, &quot;warn&quot;, &quot;error&quot;, time&quot;.</span>
<span class="c"> * Custom categories can be used as well. (opt)</span>
<span class="c"> * @param {String} src The source of the the message (opt)</span>
<span class="c"> * @return {YUI} YUI instance</span>
<span class="c"> */</span>
<span class="nx">instance</span><span class="o">.</span><span class="nx">log</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">msg</span><span class="o">,</span> <span class="nx">cat</span><span class="o">,</span> <span class="nx">src</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">Y</span> <span class="o">=</span> <span class="nx">instance</span><span class="o">,</span> <span class="nx">c</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">config</span><span class="o">,</span> <span class="nx">es</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">Env</span><span class="o">.</span><span class="nx">_eventstack</span><span class="o">,</span>
<span class="nx">bail</span> <span class="o">=</span> <span class="o">(</span><span class="nx">es</span> <span class="o">&amp;&amp;</span> <span class="nx">es</span><span class="o">.</span><span class="nx">logging</span><span class="o">);</span>
<span class="c">// suppress log message if the config is off or the event stack</span>
<span class="c"></span> <span class="c">// or the event call stack contains a consumer of the yui:log event</span>
<span class="c"></span> <span class="k">if</span> <span class="o">(</span><span class="nx">c</span><span class="o">.</span><span class="nx">debug</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="nx">bail</span><span class="o">)</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">c</span><span class="o">.</span><span class="nx">useConsole</span> <span class="o">&amp;&amp;</span> <span class="k">typeof</span> <span class="nx">console</span> <span class="o">!=</span> <span class="s1">&#39;undefined&#39;</span><span class="o">)</span> <span class="o">{</span>
<span class="c">// apply source filters</span>
<span class="c"></span> <span class="k">if</span> <span class="o">(</span><span class="nx">src</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">exc</span> <span class="o">=</span> <span class="nx">c</span><span class="o">.</span><span class="nx">logExclude</span><span class="o">,</span> <span class="nx">inc</span> <span class="o">=</span> <span class="nx">c</span><span class="o">.</span><span class="nx">logInclude</span><span class="o">;</span>
<span class="c">// console.log(&#39;checking src filter: &#39; + src + &#39;, inc: &#39; + inc + &#39;, exc: &#39; + exc);</span>
<span class="c"></span>
<span class="k">if</span> <span class="o">(</span><span class="nx">inc</span> <span class="o">&amp;&amp;</span> <span class="o">!(</span><span class="nx">src</span> <span class="k">in</span> <span class="nx">inc</span><span class="o">))</span> <span class="o">{</span>
<span class="c">// console.log(&#39;bail: inc list found, but src is not in list: &#39; + src);</span>
<span class="c"></span> <span class="nx">bail</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span>
<span class="o">}</span> <span class="k">else</span> <span class="k">if</span> <span class="o">(</span><span class="nx">exc</span> <span class="o">&amp;&amp;</span> <span class="o">(</span><span class="nx">src</span> <span class="k">in</span> <span class="nx">exc</span><span class="o">))</span> <span class="o">{</span>
<span class="c">// console.log(&#39;bail: exc list found, and src is in it: &#39; + src);</span>
<span class="c"></span> <span class="nx">bail</span> <span class="o">=</span> <span class="kc">true</span><span class="o">;</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="k">if</span> <span class="o">(!</span><span class="nx">bail</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">f</span> <span class="o">=</span> <span class="o">(</span><span class="nx">cat</span> <span class="o">&amp;&amp;</span> <span class="nx">console</span><span class="o">[</span><span class="nx">cat</span><span class="o">])</span> <span class="o">?</span> <span class="nx">cat</span> <span class="o">:</span> <span class="s1">&#39;log&#39;</span><span class="o">,</span>
<span class="nx">m</span> <span class="o">=</span> <span class="o">(</span><span class="nx">src</span><span class="o">)</span> <span class="o">?</span> <span class="nx">src</span> <span class="o">+</span> <span class="s1">&#39;: &#39;</span> <span class="o">+</span> <span class="nx">msg</span> <span class="o">:</span> <span class="nx">msg</span><span class="o">;</span>
<span class="nx">console</span><span class="o">[</span><span class="nx">f</span><span class="o">](</span><span class="nx">m</span><span class="o">);</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="c">// category filters are not used to suppress the log event</span>
<span class="c"></span> <span class="c">// so that the data can be stored and displayed later.</span>
<span class="c"></span> <span class="k">if</span> <span class="o">(</span><span class="nx">Y</span><span class="o">.</span><span class="nx">fire</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">fire</span><span class="o">(</span><span class="s1">&#39;yui:log&#39;</span><span class="o">,</span> <span class="nx">msg</span><span class="o">,</span> <span class="nx">cat</span><span class="o">,</span> <span class="nx">src</span><span class="o">);</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="k">return</span> <span class="nx">Y</span><span class="o">;</span>
<span class="o">};</span>
<span class="o">},</span> <span class="s2">&quot;@VERSION@&quot;</span><span class="o">);</span>
</pre></div>
</div>
</div>
</div>
<div class="yui-b">
<div class="nav">
<div class="module">
<h4>Modules</h4>
<ul class="content">
<li class=""><a href="module_anim.html">anim</a></li>
<li class=""><a href="module_anim-color.html">anim-color</a></li>
<li class=""><a href="module_anim-curve.html">anim-curve</a></li>
<li class=""><a href="module_anim-easing.html">anim-easing</a></li>
<li class=""><a href="module_anim-scroll.html">anim-scroll</a></li>
<li class=""><a href="module_anim-xy.html">anim-xy</a></li>
<li class=""><a href="module_attribute.html">attribute</a></li>
<li class=""><a href="module_base.html">base</a></li>
<li class=""><a href="module_dd-plugin.html">dd-plugin</a></li>
<li class=""><a href="module_event.html">event</a></li>
<li class=""><a href="module_get.html">get</a></li>
<li class=""><a href="module_io.html">io</a></li>
<li class=""><a href="module_loader.html">loader</a></li>
<li class=""><a href="module_node.html">node</a></li>
<li class=""><a href="module_node-class.html">node-class</a></li>
<li class=""><a href="module_node-region.html">node-region</a></li>
<li class=""><a href="module_node-screen.html">node-screen</a></li>
<li class=""><a href="module_Queue.html">Queue</a></li>
<li class="selected"><a href="module_yui.html">yui</a></li>
</ul>
</div>
<div class="module">
<h4>Classes</h4>
<ul class="content">
<li class=""><a href="Array.html">Array</a></li>
<li class=""><a href="Lang.html">Lang</a></li>
<li class=""><a href="Object.html">Object</a></li>
<li class=""><a href="UA.html">UA</a></li>
<li class=""><a href="YUI.html">YUI</a></li>
</ul>
</div>
<div class="module">
<h4>Files</h4>
<ul class="content">
<li class=""><a href="yui-array.js.html">yui-array.js</a></li>
<li class=""><a href="yui-core.js.html">yui-core.js</a></li>
<li class=""><a href="yui-dump.js.html">yui-dump.js</a></li>
<li class=""><a href="yui-init.js.html">yui-init.js</a></li>
<li class=""><a href="yui-lang.js.html">yui-lang.js</a></li>
<li class=""><a href="yui-later.js.html">yui-later.js</a></li>
<li class="selected"><a href="yui-log.js.html">yui-log.js</a></li>
<li class=""><a href="yui-object.js.html">yui-object.js</a></li>
<li class=""><a href="yui-ua.js.html">yui-ua.js</a></li>
<li class=""><a href="yui.js.html">yui.js</a></li>
</ul>
</div>
</div>
</div>
</div>
<div id="ft">
<hr />
Copyright &copy; 2008 Yahoo! Inc. All rights reserved.
</div>
</div>
</body>
</html>