0a9ea5af1a181db93d831604b9736ca720521096.svn-base
9.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<!DOCTYPE html> <html> <head> <title>exception.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> exception.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"> * exception.js: Utility methods for gathing information about uncaughtExceptions.</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">os</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">'os'</span><span class="p">),</span>
<span class="nx">stackTrace</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">'stack-trace'</span><span class="p">);</span>
<span class="kd">var</span> <span class="nx">exception</span> <span class="o">=</span> <span class="nx">exports</span><span class="p">;</span>
<span class="nx">exception</span><span class="p">.</span><span class="nx">getAllInfo</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="p">{</span>
<span class="nx">process</span><span class="o">:</span> <span class="nx">exception</span><span class="p">.</span><span class="nx">getProcessInfo</span><span class="p">(),</span>
<span class="nx">os</span><span class="o">:</span> <span class="nx">exception</span><span class="p">.</span><span class="nx">getOsInfo</span><span class="p">(),</span>
<span class="nx">trace</span><span class="o">:</span> <span class="nx">exception</span><span class="p">.</span><span class="nx">getTrace</span><span class="p">(</span><span class="nx">err</span><span class="p">)</span>
<span class="p">};</span>
<span class="p">};</span>
<span class="nx">exception</span><span class="p">.</span><span class="nx">getProcessInfo</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">pid</span><span class="o">:</span> <span class="nx">process</span><span class="p">.</span><span class="nx">pid</span><span class="p">,</span>
<span class="nx">uid</span><span class="o">:</span> <span class="nx">process</span><span class="p">.</span><span class="nx">getuid</span><span class="p">(),</span>
<span class="nx">gid</span><span class="o">:</span> <span class="nx">process</span><span class="p">.</span><span class="nx">getgid</span><span class="p">(),</span>
<span class="nx">cwd</span><span class="o">:</span> <span class="nx">process</span><span class="p">.</span><span class="nx">cwd</span><span class="p">(),</span>
<span class="nx">execPath</span><span class="o">:</span> <span class="nx">process</span><span class="p">.</span><span class="nx">execPath</span><span class="p">,</span>
<span class="nx">version</span><span class="o">:</span> <span class="nx">process</span><span class="p">.</span><span class="nx">version</span><span class="p">,</span>
<span class="nx">argv</span><span class="o">:</span> <span class="nx">process</span><span class="p">.</span><span class="nx">argv</span><span class="p">,</span>
<span class="nx">memoryUsage</span><span class="o">:</span> <span class="nx">process</span><span class="p">.</span><span class="nx">memoryUsage</span><span class="p">()</span>
<span class="p">};</span>
<span class="p">};</span>
<span class="nx">exception</span><span class="p">.</span><span class="nx">getOsInfo</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">loadavg</span><span class="o">:</span> <span class="nx">os</span><span class="p">.</span><span class="nx">loadavg</span><span class="p">(),</span>
<span class="nx">uptime</span><span class="o">:</span> <span class="nx">os</span><span class="p">.</span><span class="nx">uptime</span><span class="p">()</span>
<span class="p">};</span>
<span class="p">};</span>
<span class="nx">exception</span><span class="p">.</span><span class="nx">getTrace</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">trace</span> <span class="o">=</span> <span class="nx">err</span> <span class="o">?</span> <span class="nx">stackTrace</span><span class="p">.</span><span class="nx">parse</span><span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="o">:</span> <span class="nx">stackTrace</span><span class="p">.</span><span class="nx">get</span><span class="p">();</span>
<span class="k">return</span> <span class="nx">trace</span><span class="p">.</span><span class="nx">map</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">site</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="p">{</span>
<span class="nx">column</span><span class="o">:</span> <span class="nx">site</span><span class="p">.</span><span class="nx">getColumnNumber</span><span class="p">(),</span>
<span class="nx">file</span><span class="o">:</span> <span class="nx">site</span><span class="p">.</span><span class="nx">getFileName</span><span class="p">(),</span>
<span class="kd">function</span><span class="o">:</span> <span class="nx">site</span><span class="p">.</span><span class="nx">getFunctionName</span><span class="p">(),</span>
<span class="nx">line</span><span class="o">:</span> <span class="nx">site</span><span class="p">.</span><span class="nx">getLineNumber</span><span class="p">(),</span>
<span class="nx">method</span><span class="o">:</span> <span class="nx">site</span><span class="p">.</span><span class="nx">getMethodName</span><span class="p">(),</span>
<span class="kr">native</span><span class="o">:</span> <span class="nx">site</span><span class="p">.</span><span class="nx">isNative</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>