Code Monkey home page Code Monkey logo

error-formatter's Introduction

error-formatter

NPM version build status David deps node version Gittip

Formate error to string or json, for log use.

Install

npm install error-formatter

Usage

var formater = require('error-formatter');

var err = new Error('test error');
err.host = '127.0.0.1';
err.code = 'DUPLICATE';
err.url = '/error';
err.data = {foo: 'bar'};

var msg = formater(err);
var json = formater.json(err);
var both = formater.bot(err);   // yield {text: text, json: json}

yield

2014-07-07 15:11:26.421 nodejs.ErrorException: DUPLICATEError: test error (127.0.0.1)
    at Object.<anonymous> (/Users/deadhorse/git/error-formatter/test/index.test.js:15:11)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:349:32)
    at Function.Module._load (module.js:305:12)
    at Module.require (module.js:357:17)
    at require (module.js:373:17)
    at /Users/deadhorse/git/error-formatter/node_modules/mocha/lib/mocha.js:172:27
    at Array.forEach (native)
    at Mocha.loadFiles (/Users/deadhorse/git/error-formatter/node_modules/mocha/lib/mocha.js:169:14)
    at Mocha.run (/Users/deadhorse/git/error-formatter/node_modules/mocha/lib/mocha.js:356:31)
    at Object.<anonymous> (/Users/deadhorse/git/error-formatter/node_modules/mocha/bin/_mocha:366:16)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:349:32)
    at Function.Module._load (module.js:305:12)
    at Function.Module.runMain (module.js:490:10)
    at startup (node.js:124:16)
    at node.js:803:3
pid: 91000
Host: dead-horsedeMacBook-Pro.local
URL: /error
Data: {"foo":"bar"}
2014-07-07 15:11:26.421

License

MIT

error-formatter's People

Contributors

dead-horse avatar fengmk2 avatar jacksontian avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.