uuid-logger
Unique Id based logger for node requests
Last updated 2 years ago by yogeshyadav108098 .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install uuid-logger 
SYNC missed versions from official npm registry.

Request based log tracker

Request based log tracker

Node library to track requests landing on a server for better log tracking. No need to do anything, library takes care of everyting.

Preface

In normal scenario, tracking and processing request is little typical. This library is trying to make that simpler and effective. You can just import and add logs like all other logger. Library will take care of differentiating between different requests.

Features

  1. Adds Unique Identifier to logs.
  2. Differentiate and tracks different requests.

Getting started.

Request tracking example after using this logger RequestTracking

Install

npm install --save uuid-logger

Usage

App.js : Add unique Identifier to each request


const Express = require('express');
var Logger = new (require('uuid-logger'))();

let App = Express();
App.use(Logger.addRequestId());

Logger.js : Require Uuid Logger, add customized formatter

  1. Add Console Logger
// In logger.js
const _ = require('lodash');
const Moment = require('moment');
const Logger = new (require('uuid-logger'))();

const formatter = (logEntry) => {
    let timeStamp = Moment().format('YYYY-MM-DD HH:mm:ss.MS');
    return timeStamp + ' - ' + logEntry.level + ': ' + _.get(logEntry, 'meta.message');
};

Logger.addTransport({
    console: {
        name: 'Console Logger',
        level: 'info',
        colorize: true,
        formatter: formatter
    }
});
module.exports = Logger.getLogger();
  1. Add File Logger
// In logger.js
const _ = require('lodash');
const Moment = require('moment');
const Logger = new (require('uuid-logger'))();

const formatter = (logEntry) => {
    let timeStamp = Moment().format('YYYY-MM-DD HH:mm:ss.MS');
    return timeStamp + ' - ' + logEntry.level + ': ' + _.get(logEntry, 'meta.message');
};

Logger.addTransport({
    file: {
        fileName: 'tempX.log',
        filePath: '/tmp',
        level: 'info',
        colorize: false,
        json: false,
        zippedArchive: true,
        maxDays: 15,
        formatter: formatter
    }
});
module.exports = Logger.getLogger();
  1. Add Slack Logger
// In logger.js
const _ = require('lodash');
const Moment = require('moment');
const Logger = new (require('uuid-logger'))();

const formatter = (logEntry) => {
    let timeStamp = Moment().format('YYYY-MM-DD HH:mm:ss.MS');
    return timeStamp + ' - ' + logEntry.level + ': ' + _.get(logEntry, 'meta.message');
};

Logger.addTransport({
    slack: {
        webHookUrl: "https://hooks.slack.com/services/XXXXXX/XXXXXX/XXXXXX",
        channel: "#channelname",
        username: "Bot",
        level: 'info'
    }
});
module.exports = Logger.getLogger();

How to contribute

Have an idea? Found a bug? See how to contribute.

Have a problem? Come chat with us!

LinkedIn
Twitter
Github
Gmail

Maintained by

Yogesh Yadav

Support my projects

I open-source almost everything I can, and I try to reply everyone needing help using these projects. Obviously, this takes time. You can integrate and use these projects in your applications for free! You can even change the source code and redistribute (even resell it).

However, if you get some profit from this or just want to encourage me to continue creating stuff, there are few ways you can do it:

  • Starring and sharing the projects you like
  • Paytm You can make one-time donations via Paytm (+91-7411000282). I'll probably buy a coffee.
  • UPI You can make one-time donations via UPI (7411000282@paytm).
  • Bitcoin You can send me bitcoins at this address (or scanning the code below): 3BKvX4Rck6B69JZMuPFFCPif4dSctSxJQ5

Thanks!

Where is this library used?

If you are using this library in one of your projects, add it here.

License

MIT © Yogesh Yadav

Current Tags

  • 1.1.9                                ...           latest (2 years ago)

17 Versions

  • 1.1.9                                ...           2 years ago
  • 1.1.8                                ...           2 years ago
  • 1.1.6                                ...           2 years ago
  • 1.1.5                                ...           2 years ago
  • 1.1.3                                ...           2 years ago
  • 1.1.2                                ...           2 years ago
  • 1.1.1                                ...           2 years ago
  • 1.1.0                                ...           2 years ago
  • 1.0.10                                ...           2 years ago
  • 1.0.9                                ...           2 years ago
  • 1.0.8                                ...           2 years ago
  • 1.0.6                                ...           2 years ago
  • 1.0.4                                ...           3 years ago
  • 1.0.3                                ...           3 years ago
  • 1.0.2                                ...           3 years ago
  • 1.0.1                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
Downloads
Today 0
This Week 0
This Month 2
Last Day 0
Last Week 0
Last Month 0
Dependencies (21)
Dev Dependencies (0)
None

Copyright 2014 - 2017 © taobao.org |