Send logs to SumoLogic HTTP Endpoint
npm install sumologic.jsnpm install --save sumologic.jsnpm run buildnpm run watchnpm run test---
SumoLogic module:import SumoLogic from 'sumologic.js';
``javascript
const settings = {
endpoint: "{your Sumo Logic http endpoint}",
captureConsole: true,
captureError: true,
devMode: false,
};
const sumoLogic = new SumoLogic(settings);
`
To log an info message
`javascript`
sumoLogic.info({
message: 'message',
any: 'object',
});
To log an error message
`javascript`
sumoLogic.error({
message: 'message',
any: 'object',
});
To log a warning message:
`javascript`
sumoLogic.warn({
message: 'message',
any: 'object',
});
(mandatory) provided by SumoLogic when you create an HTTP collectionsyncInterval (optional - 3000ms by default) is the frequency we're sending the logs to SumoLogic.captureConsole (optional - true by default). To send console logs to SumoLogic; it includes ('warn', 'info', 'log', 'error'). captureError (optional - true by default). To send runtime errors to SumoLogic. devMode (optional - false by default). To disable sending logs to the server, typically used to disable logging in development mode.
#### Context
It is possible to attach context to the logs. Here is how to do it:
`javascript
sumoLogic.context = {
host: http://example.com,
object_id: 22200
};
`Additional methods
SumoLogic.dump()` dump all the logs that are not sent yet to SumoLogic. One use case for this is when you need to make sure all the logs are sent before closing your application.