0.0.4 • Published 4 years ago

loqu v0.0.4

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

LOQU - (log queue)

Loqu makes it simple to generate app logs. Some of the features it provides are:

  • All logs are maintained in WebWorker.
  • Mutiple Logging Queues Support
  • Log payload validation expense in web-worker
  • Push your logs to API with custom headers
  • Supports Multiple retries on API-failure
  • Has dead-letter queue for logs
How to use

$ npm intall loqu
1-  import loqu from 'loqu';
...
3-  const logQueue = loqu(configuration); // 👇 configuration details

Definition for loqu configuration

configuration - Object

ParamsType - Description
eventsBufferNumber - Length of events array you want (minimum)
isPayloadValidFunction {returns boolean} - That accepts dispatched log even and checks if its valid
intervalNumber - Queue logs for Number of seconds before sending
onSuccessAPIObject - Configuration given below
onErrorAPIObject - Configuration given below
APIObject - Object

ParamsType - Description
urlString - API URL that you wish to send logs
methodString - API Method (e.g. POST, PATCH) that you wish to send logs
retryCountNumber - Try retryCount times to send logs or dead letter queue
headersObject - See Docs

Full Example

import loqu from 'loqu';

const networkConfig = {
      url: 'http://<my-app>.com/api/logs',
      method: 'POST',
      headers: {'Content-Type': 'application/json'}
      retryCount: 3,
    }

const logQueue = loqu({
      eventsBuffer: 30, // Buffer atleast 30 log events
      interval: 30, //  [optional] Attempt sending to network after *interval* seconds,
      isPayloadValid: function(payload = {}) { // [optional] fn to check if log is valid and should be buffered
      const required = ['actionName', 'actionCategory', 'startDateTime'];
      const isValidPayload = required.every(key =>
        payload.hasOwnProperty(key)
      );
      return isValidPayload; // must return boolean
    },
    onSuccess: networkConfig, // [optional] - if not set you will receieve queue of logs against onmessage
    onError: networkConfig // [optional] - if not set you will receieve queue of logs against onmessage
  });

// Now you can start sending logs
  logQueue.send({ // any payload you want to send. for example
      actionName: 'tab-switch',
      actionCategory: 'UI/Interaction',
      startDateTime: new Date()
  })

loqQueue.onmessage = function(e) { // if network call fails logQueue will send you queue of messages here
    console.log('got sent loqu: ', e.data);
}
loqQueue.onmessage = function(e) {
    console.log('Error in logQueue: ', e.data);
}

Development is continued. Feel free to raise issues or features If want to contribute! WELCOME!!!

License

MIT