Giter Site home page Giter Site logo

bunyan-decorator's Introduction

#bunyan-decorator

bunyan-decorator enables you to log the result of functions that return a promise or a value.

Install

npm install bunyan-decorator

Usage

const bunyan = require('bunyan');
const bunyand = require ('./bunyan-decorator');

const l = new Logger(bunyan.createLogger({
  name: 'my-app'
}));

const log = l.log;

class MyClass {

  // Decorator your class method to log it
  @log(Level.info)
  searchById(id) {
    return MySearchService.byId(id);
  }
}

Extractors

Extractors enable you to modify the result logged by the bunyan decorator

class MyClass {

  // This extractor will transform the result nil, thus not return value is logged
  @log(Level.info, { extractor: result => {} })
  searchById(id) {
    return MySearchService.byId(id);
  }
}

Example log record

Note all log records include all default bunyan property as well as the class name, the class method, the elapsed time, and the result (unless an extractor is used).

Pretty

02:12:41.894Z  INFO my-app: SchoolsService.all(...) (module=SchoolsService, method=all(...), elapsedTime=428.553181)
    result: [
      {
        "id": "sampleschoolid1",
        "location": {
          "geo": {
            "lat": -1,
            "lon": -1
          },
          "address": {
            "street": "10 street rd",
            "city": "littleton",
            "state": "ma",
            "zip": "01146"
          }
        },
        "type": "school",
        "name": "sampleschoolid1",
        "district": {
          "id": "district-1",
          "name": "District One",
          "type": "district"
        },
        "group": {
          "name": "School Group One"
        },
        "created": "2017-02-16T13:36:01.781Z"
      }
    ]

Raw

"name":"my-app","hostname":"Carmines-MacBook-Pro-7.local","pid":58820,"level":30,"module":"ExpressServer","method":"listen","msg":"up
 and running in development @: Carmines-MacBook-Pro-7.local on port: 3003}","time":"2017-02-24T02:15:38.065Z","v":0}
{"name":"ecl-registration","hostname":"Carmines-MacBook-Pro-7.local","pid":58820,"level":30,"module":"SchoolsService","method":"all(...)","elaps
edTime":404.09158199999996,"result":[{"id":"sampleschoolid1","location":{"geo":{"lat":-1,"lon":-1},"address":{"street":"10 street rd","city":"li
ttleton","state":"ma","zip":"01146"}},"type":"school","name":"sampleschoolid1","district":{"id":"district-1","name":"District One","type":"distr
ict"},"group":{"name":"School Group One"},"created":"2017-02-16T13:36:01.781Z"}],"msg":"SchoolsService.all(...)","time":"2017-02-24T02:15:41.487
Z","v":0}
{"name":"ecl-registration","hostname":"Carmines-MacBook-Pro-7.local","pid":58820,"level":30,"module":"Controller","method":"all(...)","elapsedTi
me":410.745346,"msg":"Controller.all(...)","time":"2017-02-24T02:15:41.494Z","v":0}

License

MIT

bunyan-decorator's People

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.