Skip to content
Browse files

v1.0.0. Modularized...

- Modularized
- Added [docco](http://jashkenas.github.com/docco/) docs
- Debug line is now only outputted if the log level is 7
- Added `setLevel(level)`
- Added `History.md`
- Added new screenshots
- `cli-color` dependency now accepts revisions
  • Loading branch information...
1 parent 65c6ba4 commit 06d726661f933d8c8b30422cb722aa66d3e0010a @balupton balupton committed Feb 11, 2012
Showing with 499 additions and 44 deletions.
  1. +13 −0 History.md
  2. +9 −0 LICENSE.txt
  3. +24 −0 Makefile
  4. +20 −39 README.md
  5. +12 −0 docs/caterpillar.html
  6. +186 −0 docs/docco.css
  7. +102 −0 docs/formatter.html
  8. +85 −0 docs/logger.html
  9. +37 −0 docs/transport.html
  10. +4 −2 examples/console.coffee
  11. +2 −1 lib/formatter.coffee
  12. +5 −2 package.json
View
13 History.md
@@ -0,0 +1,13 @@
+## History
+
+- v1.0 February 11, 2012
+ - Modularised
+ - Added [docco](http://jashkenas.github.com/docco/) docs
+ - Debug line is now only outputted if the log level is 7
+ - Added `setLevel(level)`
+ - Added `History.md`
+ - Added new screenshots
+ - `cli-color` dependency now accepts revisions
+
+- v0.1 September 5, 2011
+ - Initial commit
View
9 LICENSE.txt
@@ -0,0 +1,9 @@
+(The MIT License)
+
+Copyright (c) 2011-2012 Benjamin Lupton <b@lupton.cc>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
24 Makefile
@@ -0,0 +1,24 @@
+test:
+ ./node_modules/.bin/mocha \
+ --reporter spec \
+ --ui bdd \
+ --ignore-leaks \
+ --growl
+
+test-debug:
+ node --debug-brk ./node_modules/.bin/mocha \
+ --reporter spec \
+ --ui bdd \
+ --ignore-leaks \
+ --growl
+
+docs:
+ ./node_modules/.bin/docco lib/*.coffee
+
+example:
+ coffee ./examples/console.coffee
+
+example-debug:
+ coffee ./examples/console.coffee -d
+
+.PHONY: test
View
59 README.md
@@ -5,44 +5,25 @@ Caterpillar is an awesome, simple, intuitive console logger for [node.js](http:/
## Example
-### [examples/console.coffee](https://github.com/balupton/caterpillar.npm/blob/master/examples/console.coffee)
-
-<img src="https://github.com/balupton/caterpillar.npm/raw/master/media/caterpillar.npm.png"/>
-
-``` coffeescript
-# Requires
-caterpillar = require "#{__dirname}/../lib/caterpillar.coffee"
-
-# Create
-logger = new caterpillar.Logger
- transports:
- level: 7
-
-# Logs
-for own name,code of logger.config.levels
- logger.log name, "this is #{name} and is level #{code}"
-
-# Standard
-logger.log ''
-logger.log 'this is awesome'
-logger.log 'this','is','awesome'
-
-# Colors
-colors = caterpillar.colors
-logger.log ''
-logger.log 'this is', colors.magenta.bold.italic.underline('awesome')
-
-# Grouping
-logger.config.autoFlush = false
-logger.log ''
-logger.log 'one'
-logger.log 'two'
-logger.log 'three'
-setTimeout(
- -> logger.flush()
- 3000
-)
-```
+### Running Normally
+
+Running the [console example](https://github.com/balupton/caterpillar.npm/blob/master/examples/console.coffee#files) with `coffee examples/console.coffee`
+
+<img src="https://github.com/balupton/caterpillar.npm/raw/master/media/caterpillar-normal.png"/>
+
+
+### Running in Debug Mode (log level 7)
+
+Running the [console example](https://github.com/balupton/caterpillar.npm/blob/master/examples/console.coffee#files) with `coffee examples/console.coffee -d`
+
+<img src="https://github.com/balupton/caterpillar.npm/raw/master/media/caterpillar-debug.png"/>
+
+When you set the log level to level 7 (debug level), then the `ConsoleFormatter` will also output a debug line, containing the time, file, function and line number of what triggered the log message.
+
+
+## Using
+
+Please refer to the [console example](https://github.com/balupton/caterpillar.npm/blob/master/examples/console.coffee#files) for usage.
# Install
@@ -76,4 +57,4 @@ Inspired by the following:
## License
Licensed under the [MIT License](http://creativecommons.org/licenses/MIT/)
-Copyright 2011 [Benjamin Arthur Lupton](http://balupton.com)
+Copyright 2011-2012 [Benjamin Arthur Lupton](http://balupton.com)
View
12 docs/caterpillar.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html> <html> <head> <title>caterpillar.coffee</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="caterpillar.html"> caterpillar.coffee </a> <a class="source" href="formatter.html"> formatter.coffee </a> <a class="source" href="logger.html"> logger.coffee </a> <a class="source" href="transport.html"> transport.coffee </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> caterpillar.coffee </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> <p>Requires</p> </td> <td class="code"> <div class="highlight"><pre><span class="p">{</span><span class="nx">cliColor</span><span class="p">,</span><span class="nx">Formatter</span><span class="p">,</span><span class="nx">ConsoleFormatter</span><span class="p">}</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s2">&quot;#{__dirname}/formatter.coffee&quot;</span><span class="p">)</span>
+<span class="p">{</span><span class="nx">Logger</span><span class="p">}</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s2">&quot;#{__dirname}/logger.coffee&quot;</span><span class="p">)</span>
+<span class="p">{</span><span class="nx">Transport</span><span class="p">,</span><span class="nx">ConsoleTransport</span><span class="p">}</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s2">&quot;#{__dirname}/transport.coffee&quot;</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>Export</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">module.exports = </span><span class="p">{</span>
+ <span class="nx">cliColor</span><span class="p">,</span>
+ <span class="nx">Formatter</span><span class="p">,</span>
+ <span class="nx">ConsoleFormatter</span><span class="p">,</span>
+ <span class="nx">Logger</span><span class="p">,</span>
+ <span class="nx">Transport</span><span class="p">,</span>
+ <span class="nx">ConsoleTransport</span>
+<span class="p">}</span>
+
+</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
View
186 docs/docco.css
@@ -0,0 +1,186 @@
+/*--------------------- Layout and Typography ----------------------------*/
+body {
+ font-family: 'Palatino Linotype', 'Book Antiqua', Palatino, FreeSerif, serif;
+ font-size: 15px;
+ line-height: 22px;
+ color: #252519;
+ margin: 0; padding: 0;
+}
+a {
+ color: #261a3b;
+}
+ a:visited {
+ color: #261a3b;
+ }
+p {
+ margin: 0 0 15px 0;
+}
+h1, h2, h3, h4, h5, h6 {
+ margin: 0px 0 15px 0;
+}
+ h1 {
+ margin-top: 40px;
+ }
+#container {
+ position: relative;
+}
+#background {
+ position: fixed;
+ top: 0; left: 525px; right: 0; bottom: 0;
+ background: #f5f5ff;
+ border-left: 1px solid #e5e5ee;
+ z-index: -1;
+}
+#jump_to, #jump_page {
+ background: white;
+ -webkit-box-shadow: 0 0 25px #777; -moz-box-shadow: 0 0 25px #777;
+ -webkit-border-bottom-left-radius: 5px; -moz-border-radius-bottomleft: 5px;
+ font: 10px Arial;
+ text-transform: uppercase;
+ cursor: pointer;
+ text-align: right;
+}
+#jump_to, #jump_wrapper {
+ position: fixed;
+ right: 0; top: 0;
+ padding: 5px 10px;
+}
+ #jump_wrapper {
+ padding: 0;
+ display: none;
+ }
+ #jump_to:hover #jump_wrapper {
+ display: block;
+ }
+ #jump_page {
+ padding: 5px 0 3px;
+ margin: 0 0 25px 25px;
+ }
+ #jump_page .source {
+ display: block;
+ padding: 5px 10px;
+ text-decoration: none;
+ border-top: 1px solid #eee;
+ }
+ #jump_page .source:hover {
+ background: #f5f5ff;
+ }
+ #jump_page .source:first-child {
+ }
+table td {
+ border: 0;
+ outline: 0;
+}
+ td.docs, th.docs {
+ max-width: 450px;
+ min-width: 450px;
+ min-height: 5px;
+ padding: 10px 25px 1px 50px;
+ overflow-x: hidden;
+ vertical-align: top;
+ text-align: left;
+ }
+ .docs pre {
+ margin: 15px 0 15px;
+ padding-left: 15px;
+ }
+ .docs p tt, .docs p code {
+ background: #f8f8ff;
+ border: 1px solid #dedede;
+ font-size: 12px;
+ padding: 0 0.2em;
+ }
+ .pilwrap {
+ position: relative;
+ }
+ .pilcrow {
+ font: 12px Arial;
+ text-decoration: none;
+ color: #454545;
+ position: absolute;
+ top: 3px; left: -20px;
+ padding: 1px 2px;
+ opacity: 0;
+ -webkit-transition: opacity 0.2s linear;
+ }
+ td.docs:hover .pilcrow {
+ opacity: 1;
+ }
+ td.code, th.code {
+ padding: 14px 15px 16px 25px;
+ width: 100%;
+ vertical-align: top;
+ background: #f5f5ff;
+ border-left: 1px solid #e5e5ee;
+ }
+ pre, tt, code {
+ font-size: 12px; line-height: 18px;
+ font-family: Monaco, Consolas, "Lucida Console", monospace;
+ margin: 0; padding: 0;
+ }
+
+
+/*---------------------- Syntax Highlighting -----------------------------*/
+td.linenos { background-color: #f0f0f0; padding-right: 10px; }
+span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }
+body .hll { background-color: #ffffcc }
+body .c { color: #408080; font-style: italic } /* Comment */
+body .err { border: 1px solid #FF0000 } /* Error */
+body .k { color: #954121 } /* Keyword */
+body .o { color: #666666 } /* Operator */
+body .cm { color: #408080; font-style: italic } /* Comment.Multiline */
+body .cp { color: #BC7A00 } /* Comment.Preproc */
+body .c1 { color: #408080; font-style: italic } /* Comment.Single */
+body .cs { color: #408080; font-style: italic } /* Comment.Special */
+body .gd { color: #A00000 } /* Generic.Deleted */
+body .ge { font-style: italic } /* Generic.Emph */
+body .gr { color: #FF0000 } /* Generic.Error */
+body .gh { color: #000080; font-weight: bold } /* Generic.Heading */
+body .gi { color: #00A000 } /* Generic.Inserted */
+body .go { color: #808080 } /* Generic.Output */
+body .gp { color: #000080; font-weight: bold } /* Generic.Prompt */
+body .gs { font-weight: bold } /* Generic.Strong */
+body .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
+body .gt { color: #0040D0 } /* Generic.Traceback */
+body .kc { color: #954121 } /* Keyword.Constant */
+body .kd { color: #954121; font-weight: bold } /* Keyword.Declaration */
+body .kn { color: #954121; font-weight: bold } /* Keyword.Namespace */
+body .kp { color: #954121 } /* Keyword.Pseudo */
+body .kr { color: #954121; font-weight: bold } /* Keyword.Reserved */
+body .kt { color: #B00040 } /* Keyword.Type */
+body .m { color: #666666 } /* Literal.Number */
+body .s { color: #219161 } /* Literal.String */
+body .na { color: #7D9029 } /* Name.Attribute */
+body .nb { color: #954121 } /* Name.Builtin */
+body .nc { color: #0000FF; font-weight: bold } /* Name.Class */
+body .no { color: #880000 } /* Name.Constant */
+body .nd { color: #AA22FF } /* Name.Decorator */
+body .ni { color: #999999; font-weight: bold } /* Name.Entity */
+body .ne { color: #D2413A; font-weight: bold } /* Name.Exception */
+body .nf { color: #0000FF } /* Name.Function */
+body .nl { color: #A0A000 } /* Name.Label */
+body .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
+body .nt { color: #954121; font-weight: bold } /* Name.Tag */
+body .nv { color: #19469D } /* Name.Variable */
+body .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
+body .w { color: #bbbbbb } /* Text.Whitespace */
+body .mf { color: #666666 } /* Literal.Number.Float */
+body .mh { color: #666666 } /* Literal.Number.Hex */
+body .mi { color: #666666 } /* Literal.Number.Integer */
+body .mo { color: #666666 } /* Literal.Number.Oct */
+body .sb { color: #219161 } /* Literal.String.Backtick */
+body .sc { color: #219161 } /* Literal.String.Char */
+body .sd { color: #219161; font-style: italic } /* Literal.String.Doc */
+body .s2 { color: #219161 } /* Literal.String.Double */
+body .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */
+body .sh { color: #219161 } /* Literal.String.Heredoc */
+body .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */
+body .sx { color: #954121 } /* Literal.String.Other */
+body .sr { color: #BB6688 } /* Literal.String.Regex */
+body .s1 { color: #219161 } /* Literal.String.Single */
+body .ss { color: #19469D } /* Literal.String.Symbol */
+body .bp { color: #954121 } /* Name.Builtin.Pseudo */
+body .vc { color: #19469D } /* Name.Variable.Class */
+body .vg { color: #19469D } /* Name.Variable.Global */
+body .vi { color: #19469D } /* Name.Variable.Instance */
+body .il { color: #666666 } /* Literal.Number.Integer.Long */
View
102 docs/formatter.html
@@ -0,0 +1,102 @@
+<!DOCTYPE html> <html> <head> <title>formatter.coffee</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="caterpillar.html"> caterpillar.coffee </a> <a class="source" href="formatter.html"> formatter.coffee </a> <a class="source" href="logger.html"> logger.coffee </a> <a class="source" href="transport.html"> transport.coffee </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> formatter.coffee </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> <p>Requires</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">util = </span><span class="nx">require</span><span class="p">(</span><span class="s1">&#39;util&#39;</span><span class="p">)</span>
+<span class="nv">cliColor = </span><span class="nx">require</span><span class="p">(</span><span class="s1">&#39;cli-color&#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> <p>Formatter</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">Formatter</span>
+ <span class="nv">config:</span>
+ <span class="nv">colors:</span>
+ <span class="mi">0</span><span class="o">:</span> <span class="s1">&#39;red&#39;</span>
+ <span class="mi">1</span><span class="o">:</span> <span class="s1">&#39;red&#39;</span>
+ <span class="mi">2</span><span class="o">:</span> <span class="s1">&#39;red&#39;</span>
+ <span class="mi">3</span><span class="o">:</span> <span class="s1">&#39;red&#39;</span>
+ <span class="mi">4</span><span class="o">:</span> <span class="s1">&#39;yellow&#39;</span>
+ <span class="mi">5</span><span class="o">:</span> <span class="s1">&#39;yellow&#39;</span>
+ <span class="mi">6</span><span class="o">:</span> <span class="s1">&#39;green&#39;</span>
+ <span class="mi">7</span><span class="o">:</span> <span class="s1">&#39;green&#39;</span>
+ <span class="nv">level: </span><span class="mi">7</span>
+
+ <span class="nv">constructor: </span><span class="nf">(config) -&gt;</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>Apply config</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">config</span> <span class="o">or=</span> <span class="p">{}</span>
+ <span class="nx">config</span><span class="p">[</span><span class="nx">key</span><span class="p">]</span> <span class="o">?=</span> <span class="nx">value</span> <span class="k">for</span> <span class="nx">own</span> <span class="nx">key</span><span class="p">,</span><span class="nx">value</span> <span class="k">of</span> <span class="nx">@config</span>
+ <span class="vi">@config = </span><span class="nx">config</span>
+
+ <span class="nv">getLevel: </span><span class="o">-&gt;</span>
+ <span class="nx">@config</span><span class="p">.</span><span class="nx">level</span> <span class="o">?</span> <span class="kc">null</span>
+
+ <span class="nv">setLevel: </span><span class="nf">(level) -&gt;</span>
+ <span class="vi">@config.level = </span><span class="nx">level</span>
+ <span class="err">@</span>
+
+ <span class="nv">padLeft: </span><span class="nf">(padding,size,msg) -&gt;</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>Prepare</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">padding = </span><span class="nb">String</span><span class="p">(</span><span class="nx">padding</span><span class="p">)</span>
+ <span class="nv">msg = </span><span class="nb">String</span><span class="p">(</span><span class="nx">msg</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>Handle</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="nx">msg</span><span class="p">.</span><span class="nx">length</span> <span class="o">&lt;</span> <span class="nx">size</span>
+ <span class="k">for</span> <span class="nx">i</span> <span class="k">in</span> <span class="p">[</span><span class="mi">0</span><span class="p">...</span><span class="nx">size</span><span class="o">-</span><span class="nx">msg</span><span class="p">.</span><span class="nx">length</span><span class="p">]</span>
+ <span class="nv">msg = </span><span class="nx">padding</span><span class="o">+</span><span class="nx">msg</span>
+ </pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <p>Return</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">msg</span>
+
+ <span class="nv">padRight: </span><span class="nf">(padding,size,msg) -&gt;</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#182;</a> </div> <p>Prepare</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">padding = </span><span class="nb">String</span><span class="p">(</span><span class="nx">padding</span><span class="p">)</span>
+ <span class="nv">msg = </span><span class="nb">String</span><span class="p">(</span><span class="nx">msg</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>Handle</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="nx">msg</span><span class="p">.</span><span class="nx">length</span> <span class="o">&lt;</span> <span class="nx">size</span>
+ <span class="k">for</span> <span class="nx">i</span> <span class="k">in</span> <span class="p">[</span><span class="mi">0</span><span class="p">...</span><span class="nx">size</span><span class="o">-</span><span class="nx">msg</span><span class="p">.</span><span class="nx">length</span><span class="p">]</span>
+ <span class="nx">msg</span> <span class="o">+=</span> <span class="nx">padding</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>Return</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">msg</span>
+
+ <span class="nv">details: </span><span class="nf">(levelCode, levelName, args) -&gt;</span></pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-10">&#182;</a> </div> <p>Prepare</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">date = </span><span class="nx">@getDate</span><span class="p">()</span>
+ <span class="p">{</span><span class="nx">file</span><span class="p">,</span><span class="nx">line</span><span class="p">,</span><span class="nx">method</span><span class="p">}</span> <span class="o">=</span> <span class="nx">@getLineInfo</span><span class="p">()</span>
+ <span class="nv">color = </span><span class="nx">@getColor</span><span class="p">(</span><span class="nx">levelCode</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-11"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-11">&#182;</a> </div> <p>Handle</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">parts = </span><span class="p">[]</span>
+ <span class="k">for</span> <span class="nx">value</span><span class="p">,</span> <span class="nx">index</span> <span class="k">in</span> <span class="nx">args</span>
+ <span class="nx">parts</span><span class="p">[</span><span class="nx">index</span><span class="p">]</span> <span class="o">=</span>
+ <span class="k">if</span> <span class="k">typeof</span> <span class="nx">value</span> <span class="o">is</span> <span class="s1">&#39;string&#39;</span>
+ <span class="nx">value</span>
+ <span class="k">else</span>
+ <span class="nx">util</span><span class="p">.</span><span class="nx">inspect</span> <span class="nx">value</span><span class="p">,</span> <span class="kc">false</span><span class="p">,</span> <span class="mi">10</span>
+ <span class="nv">message = </span><span class="nx">parts</span><span class="p">.</span><span class="nx">join</span> <span class="s1">&#39; &#39;</span></pre></div> </td> </tr> <tr id="section-12"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-12">&#182;</a> </div> <p>Return</p> </td> <td class="code"> <div class="highlight"><pre> <span class="p">{</span><span class="nx">date</span><span class="p">,</span><span class="nx">file</span><span class="p">,</span><span class="nx">line</span><span class="p">,</span><span class="nx">method</span><span class="p">,</span><span class="nx">color</span><span class="p">,</span><span class="nx">levelName</span><span class="p">,</span><span class="nx">message</span><span class="p">}</span>
+
+ <span class="nv">format: </span><span class="nf">(levelCode,levelName,args) -&gt;</span></pre></div> </td> </tr> <tr id="section-13"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-13">&#182;</a> </div> <p>Prepare</p> </td> <td class="code"> <div class="highlight"><pre> <span class="p">{</span><span class="nx">date</span><span class="p">,</span><span class="nx">className</span><span class="p">,</span><span class="nx">line</span><span class="p">,</span><span class="nx">levelName</span><span class="p">,</span><span class="nx">message</span><span class="p">}</span> <span class="o">=</span> <span class="nx">@details</span> <span class="nx">levelCode</span><span class="p">,</span> <span class="nx">levelName</span><span class="p">,</span> <span class="nx">args</span></pre></div> </td> </tr> <tr id="section-14"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-14">&#182;</a> </div> <p>Return</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="nx">@config</span><span class="p">.</span><span class="nx">level</span> <span class="o">is</span> <span class="mi">7</span></pre></div> </td> </tr> <tr id="section-15"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-15">&#182;</a> </div> <p>Debug</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">message = </span><span class="s2">&quot;[#{date}] [#{className}: #{line}] &quot;</span><span class="o">+</span><span class="nx">@padLeft</span><span class="p">(</span><span class="s1">&#39; &#39;</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="s2">&quot;#{levelName}:&quot;</span><span class="p">)</span><span class="o">+</span><span class="s2">&quot; #{message}&quot;</span>
+ <span class="k">else</span></pre></div> </td> </tr> <tr id="section-16"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-16">&#182;</a> </div> <p>Normal</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">message = </span><span class="nx">@padLeft</span><span class="p">(</span><span class="s1">&#39; &#39;</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="s2">&quot;#{levelName}:&quot;</span><span class="p">)</span><span class="o">+</span><span class="s2">&quot; #{message}&quot;</span>
+
+ <span class="nv">getColor: </span><span class="nf">(levelCode) -&gt;</span></pre></div> </td> </tr> <tr id="section-17"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-17">&#182;</a> </div> <p>Return</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">color =</span>
+ <span class="k">if</span> <span class="nx">@config</span><span class="p">.</span><span class="nx">colors</span>
+ <span class="nx">@config</span><span class="p">.</span><span class="nx">colors</span><span class="p">[</span><span class="nx">levelCode</span><span class="p">]</span>
+ <span class="k">else</span>
+ <span class="kc">false</span>
+
+ <span class="nv">getDate: </span><span class="o">-&gt;</span></pre></div> </td> </tr> <tr id="section-18"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-18">&#182;</a> </div> <p>Prepare</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">now = </span><span class="k">new</span> <span class="nb">Date</span><span class="p">()</span>
+ <span class="nv">year = </span><span class="nx">now</span><span class="p">.</span><span class="nx">getFullYear</span><span class="p">()</span>
+ <span class="nv">month = </span><span class="nx">@padLeft</span> <span class="s1">&#39;0&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="nx">now</span><span class="p">.</span><span class="nx">getMonth</span><span class="p">()</span> <span class="o">+</span> <span class="mi">1</span>
+ <span class="nv">date = </span><span class="nx">@padLeft</span> <span class="s1">&#39;0&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="nx">now</span><span class="p">.</span><span class="nx">getDate</span><span class="p">()</span>
+ <span class="nv">hours = </span><span class="nx">@padLeft</span> <span class="s1">&#39;0&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="nx">now</span><span class="p">.</span><span class="nx">getHours</span><span class="p">()</span>
+ <span class="nv">minutes = </span><span class="nx">@padLeft</span> <span class="s1">&#39;0&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="nx">now</span><span class="p">.</span><span class="nx">getMinutes</span><span class="p">()</span>
+ <span class="nv">seconds = </span><span class="nx">@padLeft</span> <span class="s1">&#39;0&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="nx">now</span><span class="p">.</span><span class="nx">getSeconds</span><span class="p">()</span>
+ <span class="nv">ms = </span><span class="nx">@padLeft</span> <span class="s1">&#39;0&#39;</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="nx">now</span><span class="p">.</span><span class="nx">getMilliseconds</span><span class="p">()</span></pre></div> </td> </tr> <tr id="section-19"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-19">&#182;</a> </div> <p>Return</p> </td> <td class="code"> <div class="highlight"><pre> <span class="s2">&quot;#{year}-#{month}-#{date} #{hours}:#{minutes}:#{seconds}.#{ms}&quot;</span>
+
+ <span class="nv">getLineInfo: </span><span class="o">-&gt;</span></pre></div> </td> </tr> <tr id="section-20"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-20">&#182;</a> </div> <p>Prepare</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">result =</span>
+ <span class="nv">line: </span><span class="o">-</span><span class="mi">1</span>
+ <span class="nv">method: </span><span class="s1">&#39;unknown&#39;</span></pre></div> </td> </tr> <tr id="section-21"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-21">&#182;</a> </div> <p>Retrieve</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">try</span>
+ <span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span><span class="p">()</span>
+ <span class="k">catch</span> <span class="nx">e</span>
+ <span class="nv">lines = </span><span class="nx">e</span><span class="p">.</span><span class="nx">stack</span><span class="p">.</span><span class="nx">split</span><span class="p">(</span><span class="s1">&#39;\n&#39;</span><span class="p">)</span>
+ <span class="k">for</span> <span class="nx">line</span> <span class="k">in</span> <span class="nx">lines</span>
+ <span class="k">continue</span> <span class="k">if</span> <span class="nx">line</span><span class="p">.</span><span class="nx">indexOf</span><span class="p">(</span><span class="nx">__dirname</span><span class="p">)</span> <span class="o">isnt</span> <span class="o">-</span><span class="mi">1</span> <span class="o">or</span> <span class="nx">line</span><span class="p">.</span><span class="nx">indexOf</span><span class="p">(</span><span class="s1">&#39; at &#39;</span><span class="p">)</span> <span class="o">is</span> <span class="o">-</span><span class="mi">1</span>
+ <span class="nv">parts = </span><span class="nx">line</span><span class="p">.</span><span class="nx">split</span><span class="p">(</span><span class="s1">&#39;:&#39;</span><span class="p">)</span>
+ <span class="k">if</span> <span class="nx">parts</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="nx">indexOf</span><span class="p">(</span><span class="s1">&#39;(&#39;</span><span class="p">)</span> <span class="o">is</span> <span class="o">-</span><span class="mi">1</span>
+ <span class="nv">result.method = </span><span class="s1">&#39;unknown&#39;</span>
+ <span class="nv">result.file = </span><span class="nx">parts</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/^.+?\s+at\s+/</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">)</span>
+ <span class="k">else</span>
+ <span class="nv">result.method = </span><span class="nx">parts</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/^.+?\s+at\s+/</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">).</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/\s+\(.+$/</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">)</span>
+ <span class="nv">result.file = </span><span class="nx">parts</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/^.+?\(/</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">)</span>
+ <span class="nv">result.line = </span><span class="nx">parts</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
+ <span class="k">break</span>
+
+ <span class="k">return</span> <span class="nx">result</span></pre></div> </td> </tr> <tr id="section-22"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-22">&#182;</a> </div> <p>Console Formatter</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">ConsoleFormatter</span> <span class="k">extends</span> <span class="nx">Formatter</span>
+ <span class="nv">format: </span><span class="nf">(levelCode,levelName,args) -&gt;</span></pre></div> </td> </tr> <tr id="section-23"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-23">&#182;</a> </div> <p>Prepare</p> </td> <td class="code"> <div class="highlight"><pre> <span class="p">{</span><span class="nx">date</span><span class="p">,</span><span class="nx">file</span><span class="p">,</span><span class="nx">line</span><span class="p">,</span><span class="nx">method</span><span class="p">,</span><span class="nx">color</span><span class="p">,</span><span class="nx">levelName</span><span class="p">,</span><span class="nx">message</span><span class="p">}</span> <span class="o">=</span> <span class="nx">@details</span><span class="p">(</span><span class="nx">levelCode</span><span class="p">,</span> <span class="nx">levelName</span><span class="p">,</span> <span class="nx">args</span><span class="p">)</span>
+ </pre></div> </td> </tr> <tr id="section-24"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-24">&#182;</a> </div> <p>Check</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="o">!</span><span class="nx">message</span>
+ <span class="nx">message</span>
+ <span class="k">else</span></pre></div> </td> </tr> <tr id="section-25"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-25">&#182;</a> </div> <p>Mappings</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">color = </span><span class="nx">color</span> <span class="o">and</span> <span class="nx">cliColor</span><span class="p">[</span><span class="nx">color</span><span class="p">]</span> <span class="o">or</span> <span class="nf">(str) -&gt;</span> <span class="nx">str</span>
+ <span class="nv">levelName = </span><span class="nx">color</span><span class="p">(</span><span class="nx">levelName</span><span class="o">+</span><span class="s1">&#39;:&#39;</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-26"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-26">&#182;</a> </div> <p>Formatters</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">debugFormatter = </span><span class="kc">false</span> <span class="c1">#cliColor.white</span>
+ <span class="nv">messageFormatter = </span><span class="nx">cliColor</span><span class="p">.</span><span class="nx">bold</span></pre></div> </td> </tr> <tr id="section-27"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-27">&#182;</a> </div> <p>Message</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">messageString = </span><span class="s2">&quot;#{levelName} #{message}&quot;</span>
+ <span class="nv">messageString = </span><span class="nx">messageFormatter</span><span class="p">(</span><span class="nx">messageString</span><span class="p">)</span> <span class="k">if</span> <span class="nx">messageFormatter</span></pre></div> </td> </tr> <tr id="section-28"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-28">&#182;</a> </div> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="nx">@config</span><span class="p">.</span><span class="nx">level</span> <span class="o">is</span> <span class="mi">7</span></pre></div> </td> </tr> <tr id="section-29"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-29">&#182;</a> </div> <p>Debug Information</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">seperator = </span><span class="s1">&#39;\n → &#39;</span>
+ <span class="nv">debugString = </span><span class="s2">&quot;[#{date}] [#{file}:#{line}] [#{method}]&quot;</span>
+ <span class="nv">debugString = </span><span class="nx">lineFormatter</span><span class="p">(</span><span class="nx">debugString</span><span class="p">)</span> <span class="k">if</span> <span class="nx">debugFormatter</span></pre></div> </td> </tr> <tr id="section-30"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-30">&#182;</a> </div> <p>Result</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">message = </span><span class="s2">&quot;#{messageString}#{seperator}#{debugString}&quot;</span>
+ <span class="k">else</span></pre></div> </td> </tr> <tr id="section-31"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-31">&#182;</a> </div> <p>Result</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">message = </span><span class="nx">messageString</span></pre></div> </td> </tr> <tr id="section-32"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-32">&#182;</a> </div> <p>Export</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">module.exports = </span><span class="p">{</span>
+ <span class="nx">cliColor</span><span class="p">,</span>
+ <span class="nx">Formatter</span><span class="p">,</span>
+ <span class="nx">ConsoleFormatter</span>
+<span class="p">}</span>
+
+</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
View
85 docs/logger.html
@@ -0,0 +1,85 @@
+<!DOCTYPE html> <html> <head> <title>logger.coffee</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="caterpillar.html"> caterpillar.coffee </a> <a class="source" href="formatter.html"> formatter.coffee </a> <a class="source" href="logger.html"> logger.coffee </a> <a class="source" href="transport.html"> transport.coffee </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> logger.coffee </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> <p>Requires</p> </td> <td class="code"> <div class="highlight"><pre><span class="p">{</span><span class="nx">Transport</span><span class="p">,</span><span class="nx">ConsoleTransport</span><span class="p">}</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s2">&quot;#{__dirname}/transport.coffee&quot;</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>Logger</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">Logger</span>
+ <span class="nv">config:</span>
+ <span class="nv">autoFlush: </span><span class="kc">true</span> <span class="c1"># (true or false) whether or not to auto flush after each message</span>
+ <span class="nv">transports: </span><span class="kc">null</span> <span class="c1"># (Transport, object, array or false)</span>
+ <span class="nv">level: </span><span class="mi">7</span>
+ <span class="nv">levels:</span>
+ <span class="nv">emergency: </span><span class="mi">0</span>
+ <span class="nv">alert: </span><span class="mi">1</span>
+ <span class="nv">critical: </span><span class="mi">2</span>
+ <span class="nv">error: </span><span class="mi">3</span>
+ <span class="nv">warning: </span><span class="mi">4</span>
+ <span class="nv">notice: </span><span class="mi">5</span>
+ <span class="nv">info: </span><span class="mi">6</span>
+ <span class="nv">debug: </span><span class="mi">7</span>
+
+ <span class="nv">emerg: </span><span class="mi">0</span>
+ <span class="nv">crit: </span><span class="mi">2</span>
+ <span class="nv">err: </span><span class="mi">3</span>
+ <span class="nv">warn: </span><span class="mi">4</span>
+ <span class="nv">note: </span><span class="mi">5</span>
+
+ <span class="nv">default: </span><span class="mi">6</span>
+
+ <span class="nv">messages: </span><span class="p">[]</span>
+ <span class="nv">formatter: </span><span class="kc">null</span>
+ <span class="nv">transports: </span><span class="p">[]</span>
+
+ <span class="nv">constructor: </span><span class="nf">(config) -&gt;</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>Prepare</p> </td> <td class="code"> <div class="highlight"><pre> <span class="vi">@messages = </span><span class="p">[]</span>
+ <span class="vi">@transports = </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>Apply config</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">config</span> <span class="o">or=</span> <span class="p">{}</span>
+ <span class="nx">config</span><span class="p">[</span><span class="nx">key</span><span class="p">]</span> <span class="o">?=</span> <span class="nx">value</span> <span class="k">for</span> <span class="nx">own</span> <span class="nx">key</span><span class="p">,</span><span class="nx">value</span> <span class="k">of</span> <span class="nx">@config</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>Apply levels</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">levels = </span><span class="p">{}</span>
+ <span class="nx">levels</span><span class="p">[</span><span class="nx">key</span><span class="p">]</span> <span class="o">?=</span> <span class="nx">value</span> <span class="k">for</span> <span class="nx">own</span> <span class="nx">key</span><span class="p">,</span><span class="nx">value</span> <span class="k">of</span> <span class="nx">config</span><span class="p">.</span><span class="nx">levels</span>
+ <span class="nv">config.levels = </span><span class="nx">levels</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <p>Apply transports</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">unless</span> <span class="nx">config</span><span class="p">.</span><span class="nx">transports</span>
+ <span class="nv">config.transports = </span><span class="k">new</span> <span class="nx">ConsoleTransport</span>
+ <span class="nx">unless</span> <span class="nx">config</span><span class="p">.</span><span class="nx">transports</span> <span class="k">instanceof</span> <span class="nb">Array</span>
+ <span class="nv">config.transports = </span><span class="p">[</span><span class="nx">config</span><span class="p">.</span><span class="nx">transports</span><span class="p">]</span>
+ <span class="k">for</span> <span class="nx">transport</span> <span class="k">in</span> <span class="nx">config</span><span class="p">.</span><span class="nx">transports</span>
+ <span class="k">if</span> <span class="nx">transport</span> <span class="k">instanceof</span> <span class="nx">Transport</span>
+ <span class="nx">@transports</span><span class="p">.</span><span class="nx">push</span> <span class="nx">transport</span>
+ <span class="k">else</span> <span class="k">if</span> <span class="nx">transport</span>
+ <span class="nx">@transports</span><span class="p">.</span><span class="nx">push</span> <span class="k">new</span> <span class="nx">ConsoleTransport</span> <span class="nx">transport</span>
+ <span class="k">delete</span> <span class="nx">config</span><span class="p">.</span><span class="nx">transports</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#182;</a> </div> <p>Level</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">@setLevel</span><span class="p">(</span><span class="nx">config</span><span class="p">.</span><span class="nx">level</span><span class="p">)</span> <span class="k">if</span> <span class="nx">config</span><span class="p">.</span><span class="nx">level</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>Apply config</p> </td> <td class="code"> <div class="highlight"><pre> <span class="vi">@config = </span><span class="nx">config</span>
+
+ <span class="nv">getLevel: </span><span class="o">-&gt;</span>
+ <span class="nx">@config</span><span class="p">.</span><span class="nx">level</span> <span class="o">?</span> <span class="kc">null</span>
+
+ <span class="nv">setLevel: </span><span class="nf">(level) -&gt;</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>Apply</p> </td> <td class="code"> <div class="highlight"><pre> <span class="vi">@config.level = </span><span class="nx">level</span>
+ <span class="k">for</span> <span class="nx">transport</span> <span class="k">in</span> <span class="nx">@transports</span>
+ <span class="nx">transport</span><span class="p">.</span><span class="nx">setLevel</span><span class="p">(</span><span class="nx">level</span><span class="p">)</span>
+ </pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-10">&#182;</a> </div> <p>Chain</p> </td> <td class="code"> <div class="highlight"><pre> <span class="err">@</span>
+
+ <span class="nv">getLevelCode: </span><span class="nf">(name) -&gt;</span></pre></div> </td> </tr> <tr id="section-11"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-11">&#182;</a> </div> <p>Return</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">@config</span><span class="p">.</span><span class="nx">levels</span><span class="p">[</span><span class="nx">name</span><span class="p">]</span> <span class="o">?</span> <span class="kc">null</span>
+
+ <span class="nv">getLevelName: </span><span class="nf">(code) -&gt;</span></pre></div> </td> </tr> <tr id="section-12"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-12">&#182;</a> </div> <p>Try to treturn the levelName</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">for</span> <span class="nx">own</span> <span class="nx">key</span><span class="p">,</span><span class="nx">value</span> <span class="k">of</span> <span class="nx">@config</span><span class="p">.</span><span class="nx">levels</span>
+ <span class="k">if</span> <span class="nx">value</span> <span class="o">is</span> <span class="nx">code</span>
+ <span class="k">return</span> <span class="nx">key</span>
+ </pre></div> </td> </tr> <tr id="section-13"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-13">&#182;</a> </div> <p>else return</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kc">null</span>
+
+ <span class="nv">log: </span><span class="nf">(level, args...) -&gt;</span></pre></div> </td> </tr> <tr id="section-14"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-14">&#182;</a> </div> <p>Log the entry</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="k">typeof</span> <span class="nx">level</span> <span class="o">is</span> <span class="s1">&#39;number&#39;</span>
+ <span class="nv">levelCode = </span><span class="nx">level</span>
+ <span class="nv">levelName = </span><span class="nx">@getLevelName</span> <span class="nx">levelCode</span>
+ <span class="k">else</span>
+ <span class="nv">levelName = </span><span class="nx">level</span>
+ <span class="nv">levelCode = </span><span class="nx">@getLevelCode</span> <span class="nx">levelName</span>
+ <span class="nv">levelName = </span><span class="nx">@getLevelName</span> <span class="nx">levelCode</span>
+ <span class="nx">unless</span> <span class="nx">levelCode</span><span class="o">?</span>
+ <span class="nv">levelCode = </span><span class="nx">@getLevelCode</span> <span class="s1">&#39;default&#39;</span>
+ <span class="nv">levelName = </span><span class="nx">@getLevelName</span> <span class="nx">levelCode</span>
+ <span class="nx">args</span><span class="p">.</span><span class="nx">unshift</span><span class="p">(</span><span class="nx">level</span><span class="p">)</span>
+ </pre></div> </td> </tr> <tr id="section-15"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-15">&#182;</a> </div> <p>Write the entry?</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="nx">@config</span><span class="p">.</span><span class="nx">autoFlush</span>
+ <span class="nx">@write</span> <span class="nx">levelCode</span><span class="p">,</span><span class="nx">levelName</span><span class="p">,</span><span class="nx">args</span>
+ <span class="k">else</span>
+ <span class="nx">@messages</span><span class="p">.</span><span class="nx">push</span> <span class="p">{</span><span class="nx">levelCode</span><span class="p">,</span><span class="nx">levelName</span><span class="p">,</span><span class="nx">args</span><span class="p">}</span>
+ </pre></div> </td> </tr> <tr id="section-16"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-16">&#182;</a> </div> <p>Chain</p> </td> <td class="code"> <div class="highlight"><pre> <span class="err">@</span>
+
+ <span class="nv">flush: </span><span class="o">-&gt;</span></pre></div> </td> </tr> <tr id="section-17"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-17">&#182;</a> </div> <p>Write messages</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">for</span> <span class="p">{</span><span class="nx">levelCode</span><span class="p">,</span><span class="nx">levelName</span><span class="p">,</span><span class="nx">args</span><span class="p">}</span> <span class="k">in</span> <span class="nx">@messages</span>
+ <span class="nx">@write</span> <span class="nx">levelCode</span><span class="p">,</span><span class="nx">levelName</span><span class="p">,</span><span class="nx">args</span></pre></div> </td> </tr> <tr id="section-18"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-18">&#182;</a> </div> <p>Chain</p> </td> <td class="code"> <div class="highlight"><pre> <span class="err">@</span>
+
+ <span class="nv">write: </span><span class="nf">(levelCode,levelName,args) -&gt;</span></pre></div> </td> </tr> <tr id="section-19"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-19">&#182;</a> </div> <p>Write the message</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">for</span> <span class="nx">transport</span> <span class="k">in</span> <span class="nx">@transports</span>
+ <span class="nx">transport</span><span class="p">.</span><span class="nx">write</span> <span class="nx">levelCode</span><span class="p">,</span><span class="nx">levelName</span><span class="p">,</span><span class="nx">args</span>
+ </pre></div> </td> </tr> <tr id="section-20"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-20">&#182;</a> </div> <p>Chain</p> </td> <td class="code"> <div class="highlight"><pre> <span class="err">@</span></pre></div> </td> </tr> <tr id="section-21"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-21">&#182;</a> </div> <p>Export</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">module.exports = </span><span class="p">{</span>
+ <span class="nx">Logger</span>
+<span class="p">}</span>
+
+</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
View
37 docs/transport.html
@@ -0,0 +1,37 @@
+<!DOCTYPE html> <html> <head> <title>transport.coffee</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="caterpillar.html"> caterpillar.coffee </a> <a class="source" href="formatter.html"> formatter.coffee </a> <a class="source" href="logger.html"> logger.coffee </a> <a class="source" href="transport.html"> transport.coffee </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> transport.coffee </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> <p>Requires</p> </td> <td class="code"> <div class="highlight"><pre><span class="p">{</span><span class="nx">Formatter</span><span class="p">,</span><span class="nx">ConsoleFormatter</span><span class="p">}</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s2">&quot;#{__dirname}/formatter.coffee&quot;</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>Transport</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">Transport</span>
+ <span class="nv">config:</span>
+ <span class="nv">level: </span><span class="mi">7</span>
+ <span class="nv">formatter: </span><span class="kc">null</span> <span class="c1"># (Formatter, object or false)</span>
+
+ <span class="nv">constructor: </span><span class="nf">(config) -&gt;</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>Apply config</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">config</span> <span class="o">or=</span> <span class="p">{}</span>
+ <span class="nx">config</span><span class="p">[</span><span class="nx">key</span><span class="p">]</span> <span class="o">?=</span> <span class="nx">value</span> <span class="k">for</span> <span class="nx">own</span> <span class="nx">key</span><span class="p">,</span><span class="nx">value</span> <span class="k">of</span> <span class="nx">@config</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>Apply formater</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="nx">config</span><span class="p">.</span><span class="nx">formatter</span> <span class="k">instanceof</span> <span class="nx">Formatter</span>
+ <span class="vi">@formatter = </span><span class="nx">config</span><span class="p">.</span><span class="nx">formatter</span>
+ <span class="k">else</span>
+ <span class="vi">@formatter = </span><span class="k">new</span> <span class="nx">ConsoleFormatter</span> <span class="nx">config</span><span class="p">.</span><span class="nx">formatter</span>
+ <span class="k">delete</span> <span class="nx">config</span><span class="p">.</span><span class="nx">formatter</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>Apply config</p> </td> <td class="code"> <div class="highlight"><pre> <span class="vi">@config = </span><span class="nx">config</span>
+
+ <span class="nv">getLevel: </span><span class="o">-&gt;</span>
+ <span class="nx">@config</span><span class="p">.</span><span class="nx">level</span> <span class="o">?</span> <span class="kc">null</span>
+
+ <span class="nv">setLevel: </span><span class="nf">(level) -&gt;</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <p>Apply</p> </td> <td class="code"> <div class="highlight"><pre> <span class="vi">@config.level = </span><span class="nx">level</span>
+ <span class="nx">@formatter</span><span class="p">.</span><span class="nx">setLevel</span><span class="p">(</span><span class="nx">level</span><span class="p">)</span> <span class="k">if</span> <span class="nx">@formatter</span>
+ </pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#182;</a> </div> <p>Chain</p> </td> <td class="code"> <div class="highlight"><pre> <span class="err">@</span>
+
+ <span class="nv">care: </span><span class="nf">(levelCode) -&gt;</span>
+ <span class="nx">levelCode</span> <span class="o">&lt;=</span> <span class="nx">@config</span><span class="p">.</span><span class="nx">level</span>
+
+ <span class="nv">write: </span><span class="nf">(levelCode,levelName,message) -&gt;</span>
+ <span class="k">if</span> <span class="nx">@care</span> <span class="nx">levelCode</span>
+ <span class="nv">message = </span><span class="nx">@formatter</span><span class="p">.</span><span class="nx">format</span> <span class="nx">levelCode</span><span class="p">,</span><span class="nx">levelName</span><span class="p">,</span><span class="nx">message</span>
+ <span class="k">else</span>
+ <span class="kc">null</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>Console Transport</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">ConsoleTransport</span> <span class="k">extends</span> <span class="nx">Transport</span>
+ <span class="nv">write: </span><span class="nf">(levelCode,levelName,message) -&gt;</span>
+ <span class="nv">message = </span><span class="k">super</span> <span class="nx">levelCode</span><span class="p">,</span><span class="nx">levelName</span><span class="p">,</span><span class="nx">message</span>
+ <span class="k">if</span> <span class="nx">message</span><span class="o">?</span>
+ <span class="nx">console</span><span class="p">.</span><span class="nx">log</span> <span class="nx">message</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>Export</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">module.exports = </span><span class="p">{</span>
+ <span class="nx">Transport</span><span class="p">,</span>
+ <span class="nx">ConsoleTransport</span>
+<span class="p">}</span>
+
+</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
View
6 examples/console.coffee
@@ -2,8 +2,10 @@
caterpillar = require "#{__dirname}/../lib/caterpillar.coffee"
# Create
-logger = new caterpillar.Logger
- level: 7
+logger = new caterpillar.Logger()
+logger.setLevel(if '-d' in process.argv then 7 else 6)
+# level 7 is the debug level, which will output the debug line
+# set it to level 6 or higher, to hide debug messages and ignore the debug line
# Logs
for own name,code of logger.config.levels
View
3 lib/formatter.coffee
@@ -119,7 +119,7 @@ class Formatter
catch e
lines = e.stack.split('\n')
for line in lines
- continue if line.indexOf('caterpillar.coffee') isnt -1 or line.indexOf(' at ') is -1
+ continue if line.indexOf(__dirname) isnt -1 or line.indexOf(' at ') is -1
parts = line.split(':')
if parts[0].indexOf('(') is -1
result.method = 'unknown'
@@ -129,6 +129,7 @@ class Formatter
result.file = parts[0].replace(/^.+?\(/, '')
result.line = parts[1]
break
+
return result
# Console Formatter
View
7 package.json
@@ -1,6 +1,6 @@
{
"name": "caterpillar",
- "version": "0.2.0",
+ "version": "1.0.0",
"description": "Caterpillar is an awesome, simple console logger for node.js. It supports grouping of messages, filtering log levels, colors, times, modules, custom formatters and custom transports. It's awesome.",
"homepage": "https://github.com/balupton/caterpillar.npm",
"keywords": [
@@ -43,7 +43,10 @@
"url" : "http://github.com/balupton/caterpillar.npm.git"
},
"dependencies": {
- "cli-color": "=0.1.3"
+ "cli-color": "0.1.x"
+ },
+ "devDependencies": {
+ "docco": "0.3.x"
},
"engines" : {
"node": ">=0.4.0"

0 comments on commit 06d7266

Please sign in to comment.
Something went wrong with that request. Please try again.