@futurely/futurely-nodejs-logger
v2.0.1
Published
npm init --scope=futurely npm publish --access public
Downloads
148
Readme
Futurely Logger
npm init --scope=futurely npm publish --access public
A universal logger using winston
Install
npm i futurely-nodejs-logger
Usage
Parameter-based logging
const log = require("futurely-nodejs-logger");
log.setContext("TEST");
log.setRequestId("TestId");
log.info("Use a helper method if you want", {
additional: "properties",
are: "passed along",
});
// {
// "context": "TEST",
// "requestId": "TestId",
// "additional": "properties",
// "are": "passed along",
// "level": "info",
// "message": "Use a helper method if you want",
// "timestamp": "2019-09-10T15:52:23.625Z"
// }
Error logging
const log = require("futurely-nodejs-logger");
log.setContext("TEST");
log.setRequestId("TestId");
const err = new Error("Oops. There was an error");
const { message, name, ...rest } = err;
const error = { message, name, ...rest };
log.error("Something went wrong", { error });
// {
// "context": "TEST",
// "requestId": "TestId",
// "error": { "message": "Oops. There was an error", "name": "Error" },
// "level": "error",
// "message": "Something went wrong",
// "timestamp": "2019-09-10T16:10:17.408Z"
// }
Logger API
Logs can be written by invoking the log method.
const log = require("futurely-nodejs-logger");
log.setContext("TEST");
log.setRequestId("TestId");
log.log("info", "Use a helper method if you want", {
additional: "properties",
are: "passed along",
});
// {
// "context": "TEST",
// "requestId": "TestId",
// "additional": "properties",
// "are": "passed along",
// "level": "info",
// "message": "Use a helper method if you want",
// "timestamp": "2019-09-10T15:52:23.625Z"
// }
Logger method aliases
log.error(message[, meta]);
log.warn(message[, meta]);
log.info(message[, meta]);
log.verbose(message[, meta]);
log.debug(message[, meta]);
log.silly(message[, meta]);
https://zellwk.com/blog/publish-to-npm/