Javascript

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

Javascript SDK

You're lucky! There is already a package available for JavaScript that you can easily download via npm.

Installation

npm install --save loghive

Import Libary

import { LogHive } from 'loghive';

Initialize Client

const logging = new LogHive({ 
  key: 'your-personal-api-key',
  project: 'yourprojectname'
});

Publish Event

logging.addEvent({
    group: "yourgroupname",
    event: "your-event-name",
    description: "descripton",
    notify: true
});

Push Insight

logging.addInsight({
  insight: "your-insight-name",
  value: 100
});

Set Online / Offline State

logging.setSystemOnline({
  system: "your-system-name"
});

logging.setSystemOffline({
  system: "your-system-name"
});

NPM Link: https://www.npmjs.com/package/loghive

GitHub Link: https://github.com/loghive/LogHive.SDK.Javascript

Without npm package

Push Event

import fetch from "node-fetch";

var options = {
  method: "POST",
  headers: {
    "ApiKey": "your-personal-api-key",
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    "project": "MySaas",
    "group": "yourgroupname",
    "event": "your-event-name",
    "description": "descripton",
    "notify": true
  })
};

fetch("https://api.loghive.app/v1/event/add", options).then(response => response.text()); 

Push Insight

import fetch from "node-fetch";

var options = {
  method: "POST",
  headers: {
    "ApiKey": "your-personal-api-key",
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    "project": "MySaas",
    "insight": "insightname",
    "value": 100
  })
};

fetch("https://api.loghive.app/v1/insight/add", options).then(response => response.text()); 

Set Online / Offline State

import fetch from "node-fetch";

// set online
var options = {
  method: "POST",
  headers: {
    "ApiKey": "your-personal-api-key",
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    "project": "MySaas",
    "insight": "system1",
    "value": 1
  })
};

fetch("https://api.loghive.app/v1/insight/add", options).then(response => response.text());

 // set offline
var options = {
  method: "POST",
  headers: {
    "ApiKey": "your-personal-api-key",
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    "project": "MySaas",
    "insight": "system1",
    "value": 0
  })
};

fetch("https://api.loghive.app/v1/insight/add", options).then(response => response.text()); 

Last updated