logzio-client-side
v1.0.3
Published
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.
Downloads
154
Readme
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.
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:
| Parameter | Description | |---|---| | url (required)| Url to send logs to. | | prefix | prefix to add to all logs, delete if not needed | | log Level | Log level to display in the browser console, from: ERROR, WARN, INFO. Defaults to 'WARN' and 'ERROR' | | flushInterval | Interval 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
| Parameter | Description | |---|---| | port (required)| The port you are sending your logs to. |
Logzio Shipper
| Parameter | Description | |---|---| | 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
| Parameter | Description | |---|---| | uri (required)| URI to recieve logs at | | enableCors | Enable 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