-<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"/><meta http-equiv="X-UA-Compatible" content="IE=edge"/><meta name="viewport" content="width=device-width, initial-scale=1.0"/><link rel="icon" href="/error/favicon.ico"/><title>@magic/log</title><meta name="description" content="nodejs console.log with environment aware loglevels."/><script type="application/ld+json">{"@context":"http://schema.org","@type":"website","name":"@magic/log"}</script><link rel="stylesheet" href="/error/magic.css?hdOB3ujppK" integrity="sha384-hdOB3ujppK9vk/35z7SqQe9J8B7pQ3tVL4gVjMS7lhQ9PpMpCZLMYjGO6fEbDqSk" crossorigin="anonymous"/></head><body><a class="SkipLink" href="/error/#page">Skip to Content</a><main id="Magic"><div class="Wrapper"><header class="Header"><div><a class="Logo" href="/error/"><svg viewBox="0 0 512 444"><path d="M512 444L256 0 0 444z" fill="#663695"></path><circle cx="256" cy="294" r="130" fill="#fff"></circle><circle cx="256" cy="281" r="40" fill="#663695"></circle><path d="M256 350v44m24-44l1 13c1 27 29 27 29-7m-160-72s46-47 106-47c59 0 106 47 106 47s-47 43-106 43c-60 0-106-43-106-43zm65-75a134 134 0 0189 2" class="stroke"></path><path d="M256 81v53m184 270l-43-29M72 404l43-29" class="stroke white"></path></svg></a><p>@magic/log</p><nav class="Menu"><ul><li><a href="/error/#getting-started">getting started</a></li><li><a href="/error/#install">install</a></li><li><a href="/error/#import">import</a></li><li><a href="/error/#usage">usage</a></li><li><a href="/error/#error-types">error types</a></li><li><a href="/error/#source">source</a></li></ul></nav></div></header><div class="Page" id="page"><h1>@magic/log</h1><p>nodejs console.log with environment aware loglevels.</p><ul class="GitBadges"><li><a href="https://www.npmjs.com/package/log" target="_blank" rel="noopener"><img src="https://img.shields.io/npm/v/magic/log?color=blue" height="23" role="presentation" alt="" loading="lazy"/></a></li><li><img src="https://img.shields.io/node/v/magic/log?color=blue" height="23" role="presentation" alt="" loading="lazy"/></li><li><img src="https://img.shields.io/npm/l/magic/log?color=blue" height="23" role="presentation" alt="" loading="lazy"/></li><li><a href="https://travis-ci.com/magic/log" target="_blank" rel="noopener"><img src="https://img.shields.io/travis/com/magic/log/master" height="23" role="presentation" alt="" loading="lazy"/></a></li><li><a href="https://ci.appveyor.com/project/magic/log/branch/master" target="_blank" rel="noopener"><img src="https://img.shields.io/appveyor/ci/magic/log/master.svg" height="23" role="presentation" alt="" loading="lazy"/></a></li><li><a href="https://coveralls.io/github/magic/log" target="_blank" rel="noopener"><img src="https://img.shields.io/coveralls/github/magic/log/master.svg" height="23" role="presentation" alt="" loading="lazy"/></a></li><li><a href="https://snyk.io/test/github/magic/log" target="_blank" rel="noopener"><img src="https://img.shields.io/snyk/vulnerabilities/github/magic/log.svg" height="23" role="presentation" alt="" loading="lazy"/></a></li></ul><h2 id="getting-started">getting started</h2><p>be in a nodejs project.</p><h3 id="install">install</h3><div class="Pre lines"><div class="menu"><button>copy</button></div><pre><code class="line"><span class="keyword">npm</span> i --save @magic/error</code></pre></div><h3 id="import">import</h3><div class="Pre lines"><div class="menu"><button>copy</button></div><pre><code class="line"><span class="keyword">import</span> log from <span class="string">'@magic/log'</span></code></pre></div><h2 id="usage">usage</h2><div class="Pre lines"><div class="menu"><button>copy</button></div><pre><code class="line"><span class="keyword">import</span> error from <span class="string">'@magic/error'</span></code><code class="line"></code><code class="line">err = error(<span class="string">'message'</span>, <span class="string">'name'</span>)</code><code class="line"><span class="comment">// Error { message: 'message', name: 'name', code: 'E_NAME', type: 'E', msg: 'message' }</span></code><code class="line"></code><code class="line">err = error(<span class="string">'message'</span>)</code><code class="line"><span class="comment">// Error { message: 'message', name: 'Unknown', code: 'E_UNKNOWN', type: 'E', msg: 'message' }</span></code><code class="line"></code><code class="line">err = error(new Error(<span class="string">'message'</span>))</code><code class="line"><span class="comment">// Error { message: 'message', name: 'Error', code: 'E_UNKNOWN', type: 'E', msg: 'message' }</span></code><code class="line"></code><code class="line">err = error(<span class="string">'message'</span>, <span class="string">'name with spaces'</span>)</code><code class="line"><span class="comment">// Error {</span></code><code class="line"><span class="comment">// message: 'message',</span></code><code class="line"><span class="comment">// name: 'name <span class="keyword">with</span> spaces',</span></code><code class="line"><span class="comment">// code: 'E_NAME_WITH_SPACES',</span></code><code class="line"><span class="comment">// type: 'E'</span></code><code class="line"><span class="comment">// }</span></code><code class="line"></code><code class="line">err = error([<span class="string">'message'</span>, <span class="string">'name'</span>, <span class="string">'T'</span>])</code><code class="line"><span class="comment">// Error { message: 'message', name: 'name', code: 'T_NAME', type: T, msg: 'message' }</span></code><code class="line"></code><code class="line">err = error([<span class="string">'message'</span>], <span class="string">'name'</span>, <span class="string">'T'</span>)</code><code class="line"><span class="comment">// Error { message: 'message', name: 'name', code: 'T_NAME', type: T, msg: 'message' }</span></code><code class="line"></code><code class="line">err = error([<span class="string">'message'</span>, <span class="string">'name1'</span>], <span class="string">'name2'</span>, <span class="string">'T'</span>)</code><code class="line"><span class="comment">// Error { message: 'message', name: 'name1', code: 'T_NAME1', type: T, msg: 'message' }</span></code></pre></div><h2 id="error-types">error types</h2><p>errors can have types</p><div class="Pre lines"><div class="menu"><button>copy</button></div><pre><code class="line"><span class="comment">// E is the <span class="keyword">default</span> type</span></code><code class="line">err = error(<span class="string">'message'</span>, <span class="string">'name'</span>)</code><code class="line"><span class="comment">// Error { message: 'message', name: 'name', code: 'E_NAME', type: 'E', msg: 'message' }</span></code><code class="line"></code><code class="line"><span class="comment">// warnings:</span></code><code class="line">err = error(<span class="string">'message'</span>, <span class="string">'name'</span>, <span class="string">'W'</span>)</code><code class="line"><span class="comment">// Error { message: 'message', name: 'name', code: 'W_NAME', type: 'W', msg: 'message' }</span></code><code class="line"></code><code class="line"><span class="comment">// debug:</span></code><code class="line">err = error(<span class="string">'message'</span>, <span class="string">'name'</span>, <span class="string">'D'</span>)</code><code class="line"><span class="comment">// Error { message: 'message', name: 'name', code: 'D_NAME', type: 'D', msg: 'message' }</span></code></pre></div><h2 id="source">source</h2><p>the source for this page is in the <a href="https://github.com/magic/log/tree/master/example" target="_blank" rel="noopener">example directory</a> and gets built and published to github using <a href="https://github.com/magic/core" target="_blank" rel="noopener">@magic/core</a></p></div><footer class="Footer"><div class="Container"><div class="Credits">made with a few bits of <a target="_blank" rel="noopener" href="https://magic.github.io/">magic</a></div></div></footer></div></main><script src="/error/magic.js?7glNHzaoua" integrity="sha384-7glNHzaouaHyMlnlZZizQE7dfUZyjBIexDyb0Xyf01uJUS5VVhPIsvcoe7XqXhwG" crossorigin="anonymous"></script></body></html>
0 commit comments