NodeJs

LogHive provides a simple REST API that you can use to push events and errors. Here is an example code for NodeJs:

Push Event

const https = require('https');

const options = {
  hostname: 'api.loghive.app',
  path: '/v1/event/add',
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'ApiKey your-personal-api-key'
  }
};

const data = JSON.stringify({
    'project': 'MySaas',
    'group': 'yourgroupname',
    'event': 'your-event-name',
    'description': 'descripton',
    'notify': true
  });

const req = https.request(options, (res) => {
  console.log(`Status Code: ${res.statusCode}`);

  res.on('data', (d) => {
    process.stdout.write(d);
  });
});

req.on('error', (error) => {
  console.error(error);
});

req.write(data);

req.end();

Push Insight

const https = require('https');

const options = {
  hostname: 'api.loghive.app',
  path: '/v1/insight/add',
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'ApiKey your-personal-api-key'
  }
};

const data = JSON.stringify({
    'project': 'MySaas',
    'insight': 'system1-online',
    'value': 1
  });

const req = https.request(options, (res) => {
  console.log(`Status Code: ${res.statusCode}`);

  res.on('data', (d) => {
    process.stdout.write(d);
  });
});

req.on('error', (error) => {
  console.error(error);
});

req.write(data);

req.end();

Last updated