c7a9fd7d3b1641b6c7aebfb08a90aa230cbaf3d6.svn-base 10 KB
<!DOCTYPE html>  <html> <head>   <title>transport.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>               transport.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"> * transport.js: Base Transport object for all Winston transports.</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">events</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;events&#39;</span><span class="p">),</span>
    <span class="nx">util</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;util&#39;</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>               <h3>function Transport (options)</h3>

<h4>@options {Object} Options for this instance.</h4>

<p>Constructor function for the Tranport object responsible
base functionality for all winston transports.</p>             </td>             <td class="code">               <div class="highlight"><pre><span class="kd">var</span> <span class="nx">Transport</span> <span class="o">=</span> <span class="nx">exports</span><span class="p">.</span><span class="nx">Transport</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">options</span><span class="p">)</span> <span class="p">{</span>
  <span class="nx">events</span><span class="p">.</span><span class="nx">EventEmitter</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="k">this</span><span class="p">);</span>
  
  <span class="nx">options</span>               <span class="o">=</span> <span class="nx">options</span>        <span class="o">||</span> <span class="p">{};</span>  
  <span class="k">this</span><span class="p">.</span><span class="nx">level</span>            <span class="o">=</span> <span class="nx">options</span><span class="p">.</span><span class="nx">level</span>  <span class="o">||</span> <span class="s1">&#39;info&#39;</span><span class="p">;</span>
  <span class="k">this</span><span class="p">.</span><span class="nx">silent</span>           <span class="o">=</span> <span class="nx">options</span><span class="p">.</span><span class="nx">silent</span> <span class="o">||</span> <span class="kc">false</span><span class="p">;</span>
  <span class="k">this</span><span class="p">.</span><span class="nx">handleExceptions</span> <span class="o">=</span> <span class="nx">options</span><span class="p">.</span><span class="nx">handleExceptions</span> <span class="o">||</span> <span class="kc">false</span><span class="p">;</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>Inherit from <code>events.EventEmitter</code>.</p>             </td>             <td class="code">               <div class="highlight"><pre><span class="nx">util</span><span class="p">.</span><span class="nx">inherits</span><span class="p">(</span><span class="nx">Transport</span><span class="p">,</span> <span class="nx">events</span><span class="p">.</span><span class="nx">EventEmitter</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>               <h3>function logException (msg, meta, callback)</h3>

<h4>@msg {string} Message to log</h4>

<h4>@meta {Object} <strong>Optional</strong> Additional metadata to attach</h4>

<h4>@callback {function} Continuation to respond to when complete.</h4>

<p>Logs the specified <code>msg</code>, <code>meta</code> and responds to the callback once the log
operation is complete to ensure that the event loop will not exit before
all logging has completed.</p>             </td>             <td class="code">               <div class="highlight"><pre><span class="nx">Transport</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">logException</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">msg</span><span class="p">,</span> <span class="nx">meta</span><span class="p">,</span> <span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
  <span class="kd">var</span> <span class="nx">self</span> <span class="o">=</span> <span class="k">this</span><span class="p">;</span>
  
  <span class="kd">function</span> <span class="nx">onLogged</span> <span class="p">()</span> <span class="p">{</span>
    <span class="nx">self</span><span class="p">.</span><span class="nx">removeListener</span><span class="p">(</span><span class="s1">&#39;error&#39;</span><span class="p">,</span> <span class="nx">onError</span><span class="p">);</span>
    <span class="nx">callback</span><span class="p">();</span>
  <span class="p">}</span>
  
  <span class="kd">function</span> <span class="nx">onError</span> <span class="p">()</span> <span class="p">{</span>
    <span class="nx">self</span><span class="p">.</span><span class="nx">removeListener</span><span class="p">(</span><span class="s1">&#39;logged&#39;</span><span class="p">,</span> <span class="nx">onLogged</span><span class="p">);</span>
    <span class="nx">callback</span><span class="p">();</span>
  <span class="p">}</span>
  
  <span class="k">this</span><span class="p">.</span><span class="nx">once</span><span class="p">(</span><span class="s1">&#39;logged&#39;</span><span class="p">,</span> <span class="nx">onLogged</span><span class="p">);</span>
  <span class="k">this</span><span class="p">.</span><span class="nx">once</span><span class="p">(</span><span class="s1">&#39;error&#39;</span><span class="p">,</span> <span class="nx">onError</span><span class="p">);</span>  
  <span class="k">this</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s1">&#39;error&#39;</span><span class="p">,</span> <span class="nx">msg</span><span class="p">,</span> <span class="nx">meta</span><span class="p">,</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span> <span class="p">});</span>
<span class="p">};</span>

</pre></div>             </td>           </tr>                </tbody>     </table>   </div> </body> </html>