yui-log.js.html revision ace5e2555c33a0ceddef42649f6f38fa006707cc
<html>
<head>
</head>
<body id="yahoo-com">
<div id="doc3" class="yui-t2">
<div id="hd">
<h3>yui <span class="subtitle">3.00PR1</span></h3>
<p>
> 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">"log"</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 'debug' config is true, a 'yui:log' event will be</span>
<span class="c"> * dispatched, which the logger widget and anything else</span>
<span class="c"> * can consume. If the 'useConsole' 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"> * @static</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 "info", "warn", "error", time".</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">&&</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">&&</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">&&</span> <span class="k">typeof</span> <span class="nx">console</span> <span class="o">!=</span> <span class="s1">'undefined'</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('checking src filter: ' + src + ', inc: ' + inc + ', exc: ' + exc);</span>
<span class="c"></span>
<span class="k">if</span> <span class="o">(</span><span class="nx">inc</span> <span class="o">&&</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('bail: inc list found, but src is not in list: ' + 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">&&</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"></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">&&</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">'log'</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">': '</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">'yui:log'</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">"@VERSION@"</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">
</ul>
</div>
<div class="module">
<h4>Classes</h4>
<ul class="content">
</ul>
</div>
<div class="module">
<h4>Files</h4>
<ul class="content">
</ul>
</div>
</div>
</div>
</div>
<div id="ft">
<hr />
Copyright © 2008 Yahoo! Inc. All rights reserved.
</div>
</div>
</body>
</html>