Giter Site home page Giter Site logo

wrapp-log.js's Issues

Output log attributes in predefined order

To make the log output easier to read, the attribute order should be in predefined order (with mandatory attributes serialized first).

Today the following log output generates the following string:

logger.info(randomText(), { data: randomText(), extra: randomText() })
logger.info(randomText(), { data: randomText(), extra: randomText() })
logger.info(randomText(), { data: randomText(), extra: randomText() })

> {"data":"ucu3ti","extra":"s3lpiboiv7q7z","level":"info","msg":"jgw nec936a8wq","timestamp":"2017-08-31T18:01:36.642Z"}
> {"data":" gez","extra":"lqbmek7xl1 t k","level":"info","msg":"52mgeynl4dcgmju9","timestamp":"2017-08-31T18:01:36.643Z"}
> {"data":"sqr or6o","extra":"kggl o70 uvae","level":"info","msg":" 38ls oflx8gi9ebd","timestamp":"2017-08-31T18:01:36.643Z"}

It would be easier to read by reformatting the output like:

> {"level":"info","msg":"jgw nec936a8wq","data":"ucu3ti","extra":"s3lpiboiv7q7z","timestamp":"2017-08-31T18:01:36.642Z"}
> {"level":"info","msg":"52mgeynl4dcgmju9","data":" gez","extra":"lqbmek7xl1 t k","timestamp":"2017-08-31T18:01:36.643Z"}
> {"level":"info","msg":" 38ls oflx8gi9ebd","data":"sqr or6o","extra":"kggl o70 uvae","timestamp":"2017-08-31T18:01:36.643Z"}

or

> {"level":"info","timestamp":"2017-08-31T18:01:36.642Z","msg":"jgw nec936a8wq","data":"ucu3ti","extra":"s3lpiboiv7q7z"}
> {"level":"info","timestamp":"2017-08-31T18:01:36.643Z","msg":"52mgeynl4dcgmju9","data":" gez","extra":"lqbmek7xl1 t k"}
> {"level":"info","timestamp":"2017-08-31T18:01:36.643Z","msg":" 38ls oflx8gi9ebd","data":"sqr or6o","extra":"kggl o70 uvae"}

Generate a logger object with preset additional attributes

Use case

When a logger object is passed down from a server, the request ID should always be included. When passing down the logger, that attribute will be added to the logger object and serialized together with all added attributes at log write time.

Example

Without any preset attributes (as today):

var logger = require('wrapp-log')

logger.info('Hello', { data: 123 })
> {"data":123,"level":"info","msg":"Hello","timestamp":"2017-08-31T17:13:47.376Z"}

With preset attribute (proposition):

var logger = require('wrapp-log')
var preBakedLogger = logger.withAttributes({ data: 123 })

preBakedLogger.info('Hello', { more: 'axa' })
> {"data":123,"more":"axa","level":"info","msg":"Hello","timestamp":"2017-08-31T17:17:01.813Z"}

logger.info('Hello', { more: 'axa' })
> {"more":"axa","level":"info","msg":"Hello","timestamp":"2017-08-31T17:17:01.813Z"}

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.