1
0
Fork 0
mirror of https://github.com/seejohnrun/haste-server.git synced 2024-12-26 03:57:00 +00:00
haste-server/node_modules/winston/docs/winston.html

86 lines
18 KiB
HTML
Raw Normal View History

2012-02-06 19:09:01 +00:00
<!DOCTYPE html> <html> <head> <title>winston.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="winston/common.html"> winston/common.html </a> <a class="source" href="winston/config/cli-config.html"> winston/config/cli-config.html </a> <a class="source" href="winston/config/npm-config.html"> winston/config/npm-config.html </a> <a class="source" href="winston/config/syslog-config.html"> winston/config/syslog-config.html </a> <a class="source" href="winston/config.html"> winston/config.html </a> <a class="source" href="winston/exception.html"> winston/exception.html </a> <a class="source" href="winston/logger.html"> winston/logger.html </a> <a class="source" href="winston/transports/console.html"> winston/transports/console.html </a> <a class="source" href="winston/transports/couchdb.html"> winston/transports/couchdb.html </a> <a class="source" href="winston/transports/file.html"> winston/transports/file.html </a> <a class="source" href="winston/transports/loggly.html"> winston/transports/loggly.html </a> <a class="source" href="winston/transports/transport.html"> winston/transports/transport.html </a> <a class="source" href="winston/transports/webhook.html"> winston/transports/webhook.html </a> <a class="source" href="winston/transports.html"> winston/transports.html </a> <a class="source" href="winston.html"> winston.html </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> winston.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> </td> <td class="code"> <div class="highlight"><pre><span class="cm">/*</span>
<span class="cm"> * winston.js: Top-level include defining Winston.</span>
<span class="cm"> *</span>
<span class="cm"> * (C) 2010 Charlie Robbins</span>
<span class="cm"> * MIT LICENCE</span>
<span class="cm"> *</span>
<span class="cm"> */</span>
<span class="kd">var</span> <span class="nx">winston</span> <span class="o">=</span> <span class="nx">exports</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>Expose version using <code>pkginfo</code></p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">require</span><span class="p">(</span><span class="s1">&#39;pkginfo&#39;</span><span class="p">)(</span><span class="nx">module</span><span class="p">,</span> <span class="s1">&#39;version&#39;</span><span class="p">);</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p>Include transports defined by default by winston</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">winston</span><span class="p">.</span><span class="nx">transports</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;./winston/transports&#39;</span><span class="p">);</span>
<span class="kd">var</span> <span class="nx">common</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;./winston/common&#39;</span><span class="p">);</span>
<span class="nx">winston</span><span class="p">.</span><span class="nx">hash</span> <span class="o">=</span> <span class="nx">common</span><span class="p">.</span><span class="nx">hash</span><span class="p">;</span>
<span class="nx">winston</span><span class="p">.</span><span class="nx">clone</span> <span class="o">=</span> <span class="nx">common</span><span class="p">.</span><span class="nx">clone</span><span class="p">;</span>
<span class="nx">winston</span><span class="p">.</span><span class="nx">longestElement</span> <span class="o">=</span> <span class="nx">common</span><span class="p">.</span><span class="nx">longestElement</span><span class="p">;</span>
<span class="nx">winston</span><span class="p">.</span><span class="nx">exception</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;./winston/exception&#39;</span><span class="p">);</span>
<span class="nx">winston</span><span class="p">.</span><span class="nx">config</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;./winston/config&#39;</span><span class="p">);</span>
<span class="nx">winston</span><span class="p">.</span><span class="nx">addColors</span> <span class="o">=</span> <span class="nx">winston</span><span class="p">.</span><span class="nx">config</span><span class="p">.</span><span class="nx">addColors</span><span class="p">;</span>
<span class="nx">winston</span><span class="p">.</span><span class="nx">Logger</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;./winston/logger&#39;</span><span class="p">).</span><span class="nx">Logger</span><span class="p">;</span>
<span class="nx">winston</span><span class="p">.</span><span class="nx">Transport</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;./winston/transports/transport&#39;</span><span class="p">).</span><span class="nx">Transport</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <p>We create and expose a 'defaultLogger' so that the programmer may do the
following without the need to create an instance of winston.Logger directly:</p>
<pre><code>var winston = require('winston');
winston.log('info', 'some message');
winston.error('some error');
</code></pre> </td> <td class="code"> <div class="highlight"><pre><span class="kd">var</span> <span class="nx">defaultLogger</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">winston</span><span class="p">.</span><span class="nx">Logger</span><span class="p">({</span>
<span class="nx">transports</span><span class="o">:</span> <span class="p">[</span><span class="k">new</span> <span class="nx">winston</span><span class="p">.</span><span class="nx">transports</span><span class="p">.</span><span class="nx">Console</span><span class="p">()]</span>
<span class="p">});</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">&#182;</a> </div> <p>Pass through the target methods onto `winston.</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">var</span> <span class="nx">methods</span> <span class="o">=</span> <span class="p">[</span>
<span class="s1">&#39;log&#39;</span><span class="p">,</span>
<span class="s1">&#39;add&#39;</span><span class="p">,</span>
<span class="s1">&#39;remove&#39;</span><span class="p">,</span>
<span class="s1">&#39;profile&#39;</span><span class="p">,</span>
<span class="s1">&#39;extend&#39;</span><span class="p">,</span>
<span class="s1">&#39;cli&#39;</span><span class="p">,</span>
<span class="s1">&#39;handleExceptions&#39;</span><span class="p">,</span>
<span class="s1">&#39;unhandleExceptions&#39;</span>
<span class="p">];</span>
<span class="nx">common</span><span class="p">.</span><span class="nx">setLevels</span><span class="p">(</span><span class="nx">winston</span><span class="p">,</span> <span class="kc">null</span><span class="p">,</span> <span class="nx">defaultLogger</span><span class="p">.</span><span class="nx">levels</span><span class="p">);</span>
<span class="nx">methods</span><span class="p">.</span><span class="nx">forEach</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">method</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">winston</span><span class="p">[</span><span class="nx">method</span><span class="p">]</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">defaultLogger</span><span class="p">[</span><span class="nx">method</span><span class="p">].</span><span class="nx">apply</span><span class="p">(</span><span class="nx">defaultLogger</span><span class="p">,</span> <span class="nx">arguments</span><span class="p">);</span>
<span class="p">};</span>
<span class="p">});</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <h3>function cli ()</h3>
<p>Configures the default winston logger to have the
settings for command-line interfaces: no timestamp,
colors enabled, padded output, and additional levels.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">winston</span><span class="p">.</span><span class="nx">cli</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
<span class="nx">winston</span><span class="p">.</span><span class="nx">padLevels</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
<span class="nx">common</span><span class="p">.</span><span class="nx">setLevels</span><span class="p">(</span><span class="nx">winston</span><span class="p">,</span> <span class="nx">defaultLogger</span><span class="p">.</span><span class="nx">levels</span><span class="p">,</span> <span class="nx">winston</span><span class="p">.</span><span class="nx">config</span><span class="p">.</span><span class="nx">cli</span><span class="p">.</span><span class="nx">levels</span><span class="p">);</span>
<span class="nx">defaultLogger</span><span class="p">.</span><span class="nx">setLevels</span><span class="p">(</span><span class="nx">winston</span><span class="p">.</span><span class="nx">config</span><span class="p">.</span><span class="nx">cli</span><span class="p">.</span><span class="nx">levels</span><span class="p">);</span>
<span class="nx">winston</span><span class="p">.</span><span class="nx">config</span><span class="p">.</span><span class="nx">addColors</span><span class="p">(</span><span class="nx">winston</span><span class="p">.</span><span class="nx">config</span><span class="p">.</span><span class="nx">cli</span><span class="p">.</span><span class="nx">colors</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">defaultLogger</span><span class="p">.</span><span class="nx">transports</span><span class="p">.</span><span class="nx">console</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">defaultLogger</span><span class="p">.</span><span class="nx">transports</span><span class="p">.</span><span class="nx">console</span><span class="p">.</span><span class="nx">colorize</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
<span class="nx">defaultLogger</span><span class="p">.</span><span class="nx">transports</span><span class="p">.</span><span class="nx">console</span><span class="p">.</span><span class="nx">timestamp</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">return</span> <span class="nx">winston</span><span class="p">;</span>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#182;</a> </div> <h3>function setLevels (target)</h3>
<h4>@target {Object} Target levels to use</h4>
<p>Sets the <code>target</code> levels specified on the default winston logger.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">winston</span><span class="p">.</span><span class="nx">setLevels</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">target</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">common</span><span class="p">.</span><span class="nx">setLevels</span><span class="p">(</span><span class="nx">winston</span><span class="p">,</span> <span class="nx">defaultLogger</span><span class="p">.</span><span class="nx">levels</span><span class="p">,</span> <span class="nx">target</span><span class="p">);</span>
<span class="nx">defaultLogger</span><span class="p">.</span><span class="nx">setLevels</span><span class="p">(</span><span class="nx">target</span><span class="p">);</span>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">&#182;</a> </div> <p>Define getters / setters for appropriate properties of the
default logger which need to be exposed by winston.</p> </td> <td class="code"> <div class="highlight"><pre><span class="p">[</span><span class="s1">&#39;emitErrs&#39;</span><span class="p">,</span> <span class="s1">&#39;padLevels&#39;</span><span class="p">,</span> <span class="s1">&#39;levelLength&#39;</span><span class="p">].</span><span class="nx">forEach</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">prop</span><span class="p">)</span> <span class="p">{</span>
<span class="nb">Object</span><span class="p">.</span><span class="nx">defineProperty</span><span class="p">(</span><span class="nx">winston</span><span class="p">,</span> <span class="nx">prop</span><span class="p">,</span> <span class="p">{</span>
<span class="nx">get</span><span class="o">:</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">defaultLogger</span><span class="p">[</span><span class="nx">prop</span><span class="p">];</span>
<span class="p">},</span>
<span class="nx">set</span><span class="o">:</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">val</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">defaultLogger</span><span class="p">[</span><span class="nx">prop</span><span class="p">]</span> <span class="o">=</span> <span class="nx">val</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">});</span>
<span class="p">});</span></pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-9">&#182;</a> </div> <p>@default {Object}
The default transports and exceptionHandlers for
the default winston logger.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nb">Object</span><span class="p">.</span><span class="nx">defineProperty</span><span class="p">(</span><span class="nx">winston</span><span class="p">,</span> <span class="s1">&#39;default&#39;</span><span class="p">,</span> <span class="p">{</span>
<span class="nx">get</span><span class="o">:</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
<span class="k">return</span> <span class="p">{</span>
<span class="nx">transports</span><span class="o">:</span> <span class="nx">defaultLogger</span><span class="p">.</span><span class="nx">transports</span><span class="p">,</span>
<span class="nx">exceptionHandlers</span><span class="o">:</span> <span class="nx">defaultLogger</span><span class="p">.</span><span class="nx">exceptionHandlers</span>
<span class="p">};</span>
<span class="p">}</span>
<span class="p">});</span>
</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>