1.6.0 • Published 11 months ago

wvly-logger v1.6.0

Weekly downloads
-
License
ISC
Repository
-
Last release
11 months ago

Install

npm install wvly-logger

Usage

//test.js
const  log  =  require("wvly-logger")();
log.error("error", new  Error("501"));
log.debug("DB Connected");

const  connectionString  =  "localhost:27017";
const  dbName  =  "countrySide";
const  nextObjectDetail  = {
name :  "Yaadhum Aanavan",
email :  "Yaadhum@aanavan.com"
}

// Pass multiple data in info : Pass as Object
log.info("DB Connected: ", { connectionString, dbName,nextObjectDetail });
// Second Argument as Object : it supports nested Objects as well

Note :

Second Argument MUST be Object

log.info("DB Connected: ", {object});

Output in Console

NODE_ENV undefined
logLevel : undefined
{"@timestamp":"2023-06-19T14:31:25.673Z","log.level":"error","message":"error 501","ecs":{"version":"1.6.0"},"stack":"Error: 501\n    at Object.<anonymous> (/Users/muthuMathiyazhagan/Projects/Node/kibana/test.js:2:20)\n    at Module._compile (node:internal/modules/cjs/loader:1254:14)\n    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)\n    at Module.load (node:internal/modules/cjs/loader:1117:32)\n    at Module._load (node:internal/modules/cjs/loader:958:12)\n    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)\n    at node:internal/main/run_main_module:23:47"}
{"@timestamp":"2023-06-19T14:31:25.674Z","log.level":"warn","message":"DB Connected","ecs":{"version":"1.6.0"}}
{"@timestamp":"2023-06-19T14:31:25.674Z","log.level":"info","message":"DB Connected: ","ecs":{"version":"1.6.0"},"connectionString":"localhost:27017","dbName":"countrySide","nextObjectDetail":{"name":"Yaadhum Aanavan","email":"Yaadhum@aanavan.com"}}

Note :

Debug log (#3) not logged: As by default log level is 'info' if you want to change the Level you can pass log level as argument while require the package.

const log = require("wvly-logger")('debug');

Supported levels : 1. error 2. info 3. warn 4. debug

Features

By setting your env variable LOG_LEVEL you can change the overall log level :

Try in Terminal

export LOG_LEVEL=debug // for mac and Linux

set LOG_LEVEL=warn // for windows

Example to log your req and res of API in Route handler :

//routes/genres.js
const  express  =  require("express");
const  router  =  express.Router();

router.get("/", async (request, response) => {
log.info("Request and Response : ",{request,response});
return res.status(200).send('Hello Universe..!');
});
module.exports  =  router;

Note :

Pass request and request as Second argument as Object : { request , response } ..

1.6.0

11 months ago

1.5.1

11 months ago

1.5.0

11 months ago

1.4.0

11 months ago

1.3.0

11 months ago

1.2.1

11 months ago

1.2.0

11 months ago

1.1.1

11 months ago

1.1.0

11 months ago

1.0.7

11 months ago

1.0.6

11 months ago

1.0.5

11 months ago

1.0.4

11 months ago

1.0.3

11 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago