1.0.3 • Published 3 years ago

logzio-client-side v1.0.3

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

Logzio Client-side Logger

A logger for the client-side. Using Lgzio client-side logger is a secured way to log info, debug, error and warning messages from your front-end. This logger will send all your front-end logs to your backend and then to Logz.io.

client-side-architecture

Install

npm logzio-client-side

Setting the client-side logger

Import and build the logger on your client-side, as the following example:

import * as logzioLogger from 'logzio-client-side'

const logger = logzioLogger.Logger({
  url: `http://<<your url>>api/log`
});

Parameters:

ParameterDescription
url (required)Url to send logs to.
prefixprefix to add to all logs, delete if not needed
log LevelLog level to display in the browser console, from: ERROR, WARN, INFO. Defaults to 'WARN' and 'ERROR'
flushIntervalInterval to flush logs to server

For an example of an elaborate logger configuration see our app demo.

Usage of the logger on the client-side:

    logger.info('this is an info log');
    logger.debug('this is a debug log');
    logger.warn('this is a warning log');
    logger.error('this is an error log');
    logger.flush();

Setting the server-side logger

Add the following code to your server side and change the parameters below:

const logzioServerLogger = require('logzio-client-side/server');
const app = logzioServerLogger.app;
const bodyParser = logzioServerLogger.bodyParser;
const port = <<port>>;

 const logzioShipper = logzioServerLogger.logzioLogger.createLogger({
    token: <<logzio-shipping-token>>,
    host: <<logzio-host>>,
    type: "logzio-client-side",
    debug: true
 });

app.use(bodyParser.json());

app.use(logzioServerLogger.expressEndpoint({
    uri: '/api/log', // Just an example
    logger: logzioShipper,
    enableCors: true
}));

app.listen(port, () => {
    console.log(`Listening at http://localhost:${port}`)
})

Parameters

General

ParameterDescription
port (required)The port you are sending your logs to.

Logzio Shipper

ParameterDescription
logs-shipping-token (required)Add the log shipping token for the relevant Logz.io account. This is the account you want to ship to.
logzio-host (required)Use the listener URL specific to the region of your Logz.io account. You can look it up here.

Logzio Server Logger

ParameterDescription
uri (required)URI to recieve logs at
enableCorsEnable cross-origin requests to your logging endpoint

For more configuration of the logzio-nodejs logger go to our docs. For an example of an elaborate logger configuration see our server demo.

Changelog

  • 1.0.2: Using 'require' for back-end
  • 1.0.0: Create logzio-client-side logger