1.1.15 • Published 4 years ago

@gferrand/logger-hook v1.1.15

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

Asset manager

The logger is here to help you keeping tracks of what happen in your application.

Installing

First, install the library :

npm i @gferrand/logger-hook

... and that's it ! You can now import everything you need inside your project.

The basics

First, import it in your project :

const Logger = require('@gferrand/logger-hook').Logger;

This will give you access to the first part of the logger, the ability to save what happen withing your app in a database, and to display it in the logger dashboard.

To start using it, you must first initialize it within the project :

Logger.init( $appName, $appVersion, $appPort, $loggerUrl, $usernameCbk, $userIdCbk
    
);

Both callbacks are used to extract the user informations to enrich your logs, you must provide the way for the logger to reach the informations. E.g, for both callbacks :

(req) => req.username,
(req) => req.userId

This will tell to the logger to go inside the req object, and look for the req.username to extract the username of the user who made the call.

Once it's done, wherever you want to save an important informations, such as an user requestion a password change, you can execute one of the following :

They all work as a regular console.log, and also add the content in a database with different levels of importance.

Logger.info($information1, [$information2]);

The basic level, usually used to keep track of not so important stuff.

Logger.warn($information1, [$information2]);

The middle level, to use when you need a warning about something.

Logger.error($information1, [$information2]);

The high level, use when your app is crashing.

Logger.debug($information1, [$information2]);

Give you a log without saving it into the database.

You can either pass the req from your node route or a string. If you pass the req + a string, be sure that the req is the first argument.

There's some exemples :

 Logger.info(req, 'Creating new user');
Logger.info('Updating an user');
Logger.warn('Deleting an user');

The performance checks

First, import it :

const Performance = require('@gferrand/logger-hook').Performance;

The logger is able to monitor your application and check if it's healthy or not, giving your informations on the CPU, space left available on hard drive, ect.

Performance.init( $appName, $appVersion, $appPort, $loggerUrl, $cronLikeInterval);

Same as the previous init, except the cron interval.

The logger use the cron library to schedule stuff, please check up the documentation to know what kind of string the logger is expecting for $cronLikeInterval.

Then, simply use it as a middleware for your express.

app.use(Performance.measure);

For the logger to be able to fully work, you need an extra thing, a route for him to be able to healtcheck your app :

const healthcheck = require('@gferrand/logger-hook').healthcheck;

Then create a route for the logger. E.G:

app.get('/healthcheck/' + $appName + "/" + $appVersion, healthcheck);
1.1.15

4 years ago

1.1.12

4 years ago

1.1.14

4 years ago

1.1.13

4 years ago

1.1.11

4 years ago

1.1.10

4 years ago

1.0.10

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.4

4 years ago

1.0.3

4 years ago

1.0.2

5 years ago

1.0.1

5 years ago