@wpefintech/client-logger

1.0.6 • Public • Published

Client Logger

This library contains 2 package both for client side and server side of your application.

Basic Usage

Here are the steps to start using this package.

Client

For initiation on the client side of your application, here's the one that you'll need to do:

import { initLogger } from '@wpefintech/client-logger/dist/client';

try {
    initLogger({
        enable: true, // enable the client logger
        enableEventImmediately: true, // enable error event
        endpoint: '/logging', // endpoint to send the error event throught http request
        serviceName: 'your-service-name', // your service name
    });
} catch (err) {
    console.error('[InitLogger] error when init logger');
}

If the initiation succesfull, all console.error and window unhandledrejection, error event will be automatically captured and send to the endpoint after 5s (you can change this with waitTime option when initLogger).

Server

And for the server-side (now we're only support for Express), you can attach the router package to do the logging.

import express from 'express';
import { logRouterHandler } from '@wpefintech/client-logger/dist/server';

const logRouter = logRouterHandler('/var/log/your-service'); // the argument that passed here is the path to your log files would be located.

const app = express();
const PORT = 3000;
app.post('/logging', logRouter); // endpoint for logging
app.listen(PORT, () => console.log(`Express running on port ${PORT}`));

Examples

You can see the simple example folder for the basic usage of this package. And here's the example for the result log file:

{"level":"error","time":"12/17/2020, 5:21:27 PM","pid":68624,"hostname":"BA-0000XXXX.local","ID":"071f3f160bff4defb8114b666059dbd2","service":"test-service","message":"test 1000","type":"console.error","userAgent":"Mozilla/5.0 (Linux; Android 8.0; Pixel 2 Build/OPD3.170816.012) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Mobile Safari/537.36","referrer":"","timestamp":"12/17/2020, 5:21:22 PM","href":"http://localhost:5000/","messages":["test 1000"],"v":1}

Package Sidebar

Install

npm i @wpefintech/client-logger

Weekly Downloads

17

Version

1.0.6

License

MIT

Unpacked Size

101 kB

Total Files

19

Last publish

Collaborators

  • adityalstkp
  • asep.setiawan
  • luketkpd
  • hsie01