acho-trace
Automatically logs traces
Last updated 4 years ago by kikobeats .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install acho-trace 
SYNC missed versions from official npm registry.

acho-trace


acho-trace

Last version Build Status Dependency status Dev Dependencies Status NPM Status Donate

It Envolves async/sync methods for automatically logs traces. Inspired in Apex log.

Install

$ npm install acho-trace --save

Usage

First load the plugin:

const Acho = require('acho')
Acho = require('acho-trace')(Acho)

Now when you call Acho for create a new instance, the new instance will have .trace and .traceSync methods for envolve functions and create traces.

For see it in action check examples.

API

The API provides to endpoints:

  • acho#trace
  • acho#traceSync

both methods follow the same interface:

'use strict'

var Acho = require('acho')
Acho = require('acho-trace')(Acho)

var acho = Acho()
var fn = createFnAsync()
var wrapFnOne = acho.trace(fn, {

  /*
    OPTIONAL. [default=false]
    It expresses if you are wrapping a sync function.
    Also you can use `acho#traceSync` endpoint.
  */
  sync: false,

  /*
    OPTIONAL. [default='debug']
    output level under non-error result.
  */
  level: 'debug',

  /*
    OPTIONAL. [default='error']
    output level under error result.
  */
  levelErr: 'error',

  /*
    OPTIONAL. [default='']
    context associated with the message.
  */
  context: '',

  /*
    OPTIONAL.
    Custom print function to create print
    messages under non-error.

    By default it prints the arguments
    passed in the original function.
  */
  trace: function (obj) {
    return ['executed fn with params: %j', obj]
  },

  /*
    OPTIONAL.
    Custom print function to create print
    messages under error.

    By default it prints the arguments
    passed in the original function.
  */
  traceErr: function (err) {
    return ['something bad happens: %s', err.message]
  }
})

License

MIT © Kiko Beats

Current Tags

  • 1.0.0                                ...           latest (4 years ago)

1 Versions

  • 1.0.0                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (2)
Dev Dependencies (4)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |