2.1.3 • Published 3 years ago

express-walklogger v2.1.3

Weekly downloads
4
License
ISC
Repository
-
Last release
3 years ago

A logger for just about everything. the walkover product.

Motivation

logging is very essential part of any application when you debug ,it helps you a alot. So it is useful for logging purposes.

Documentation

to install express-walklogger use

    npm i express-walklogger 

once you install the package create config.yml file and put the details below into it.make sure you put this file in your folders main directory and change the path to wherever you want to dump your data.

config.yml

app:
    projectId: mnv566zVnopjyFZbTuzkxuJ 
    authkey: 1S5J3pa2uudmWHuR5syuNZ
    include: ["*"]
    level: "INFO"
    backuptime: 0
    healthSummaryTime: 1
    flow: { 
        "/api/v1/tours/:id": {
            endpoint: tourById,
            condition:  [["res.body.data.data.price", '>=', 397], '&&', ["res.body.data.data.name", '!=', "The Forest Hiker"], '&&', ["res.body.data.data.duration", '>=', 5]]
        }
        ,
        "/api/v1/tours/tours-within/:distance/center/:latlng/unit/:unit": {
            endpoint: distance,
            condition: [["res.body.data.data[0].duration",'!=',5],"||",["res.body.data.data[0].ratingsAverage",">",4],"&&",["res.body.data.data[0].ratingsQuantity",">=",7]]
        }
        ,
        "/api/v1/users/":{
            endpoint: users,
            condition: [["res.body.data.data.name",'==',"Praveen Sharma"]]
        }
        ,
        "/api/v1/users/:id":{
            endpoint: userId,
            condition:  [["req.body.name",'==',"Praveen Sharma"],'&&',["req.method","==","PATCH"],'&&',["req.body.roles","==","admin"]]
        },
    "/api/v1/users/login":{
        endpoint: login,
        condition: [["res.statusCode",'==',200]]
    },
    "/api/v1/reviews/:id":{
        endpoint: reviews,
        condition: [["res.body.data.data.rating",'>=',5]]
    },
    "/api/v1/users/me":{
        endpoint: currentUser,
        condition: [["res.body.data.data.roles",'==',"admin"]]
    },
    "/api/v1/tours/monthly-plan/:year":{
        endpoint: monthly-plan,
        condition: [["res.body.data.plan[0].month",'>',7]]
    },
}
# set true on uncaughtAndUnhandleException if you want to log uncaughtException and unhandleRejection.
uncaughtAndUnhandleException: true,   

 
in place of projectId put your own projectId where you want to dumb the data and in place of authkey put your authkey provided by viaSocket project authkey.

in include array you need to pass the route which you allow to log.if you put "*" it means you want to allow all the route.


once you done with config file just put the code below to the top of all your route so that it will process all your route. (REMEMBER:- put this above all your route. )

const express = require('express'); const logger = require('express-walklogger');

const app = express();

app.use((req, res, next) => { let oldSend = res.send; res.send = function(data) { try { res.body = JSON.parse(data); } catch (e) { res.body = data; } oldSend.apply(res, arguments); } res.on('finish', function() { req.routePath = req.route.path; logger.setexecuteendpoint(req, res); });

next();

});

>if you want to use logger for logging uncaughtException and unhandleRejection also then just add this code below in your project :-

process.on('uncaughtException', err => { logger.uncaughtAndUnhandleException(reason); });

process.on('unhandledRejection', (reason, promise) => { logger.uncaughtAndUnhandleException(reason); })

>if you want to use logger for specific task like INFO,ERROR,WARNING use like :-

const logger = require('express-walklogger');

logger.info("dumpPoint","Success"); logger.warning("dumpPoint","Warning"); logger.error("dumpPoint","Error");

"dumpPoint" is nothing but your flow endpoint where you want to dumpdata.
for example:-`https://sokt.io/${config.app.projectId}/${dumpPoint}`

>LOGGER LEVEL 

level:"INFO"

if you set level:"INFO", then all log of "INFO","WARNING"  and "ERROR" is log.

level:"WARNING"

if you set level:"WARNING", then all log of "WARNING"  and "ERROR" is log, "INFO" log is not shown.

>logger.error("error"); error log is always log and dump.
2.1.3

3 years ago

2.1.2

3 years ago

2.1.1

3 years ago

2.1.0

3 years ago

2.0.11

4 years ago

2.0.12

4 years ago

2.0.10

4 years ago

2.0.9

4 years ago

2.0.8

4 years ago

2.0.7

4 years ago

2.0.6

4 years ago

2.0.5

4 years ago

2.0.4

4 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

1.0.22

4 years ago

1.0.21

4 years ago

1.0.20

4 years ago

1.0.19

4 years ago

1.0.18

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.11

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.1

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.0

4 years ago