mirror of
https://github.com/seejohnrun/haste-server.git
synced 2024-11-01 11:31:22 +00:00
86 lines
No EOL
18 KiB
HTML
86 lines
No EOL
18 KiB
HTML
<!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 … <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">¶</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">¶</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">'pkginfo'</span><span class="p">)(</span><span class="nx">module</span><span class="p">,</span> <span class="s1">'version'</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">¶</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">'./winston/transports'</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">'./winston/common'</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">'./winston/exception'</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">'./winston/config'</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">'./winston/logger'</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">'./winston/transports/transport'</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">¶</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">¶</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">'log'</span><span class="p">,</span>
|
|
<span class="s1">'add'</span><span class="p">,</span>
|
|
<span class="s1">'remove'</span><span class="p">,</span>
|
|
<span class="s1">'profile'</span><span class="p">,</span>
|
|
<span class="s1">'extend'</span><span class="p">,</span>
|
|
<span class="s1">'cli'</span><span class="p">,</span>
|
|
<span class="s1">'handleExceptions'</span><span class="p">,</span>
|
|
<span class="s1">'unhandleExceptions'</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">¶</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">¶</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">¶</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">'emitErrs'</span><span class="p">,</span> <span class="s1">'padLevels'</span><span class="p">,</span> <span class="s1">'levelLength'</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">¶</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">'default'</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> |