1.0.2 • Published 5 years ago

logitlib v1.0.2

Weekly downloads
4
License
ISC
Repository
-
Last release
5 years ago

Logitlib

Logitlib is a wrapper around the Logit API. It provides helper methods for doing basic log related ops.

USAGE

npm install logitlib

Basic Logging

const logit = require('logitlib')({writeKey:'aaa', apiURL: 'https://someurl.com'});
logit({
    uid: 'SOMEIDENTIFIER', // Unique identifier for the log on Logit
    ltype: 'BASICLOG', // Log type (User supplied. Some form of platform specific categorization) 
    level: 'info', // Log level (Info / Error / Warning)
    lperiod: 'log', // Log period. Useful for timeline-like logs, to mark start, stop points in an event cycle e.t.c. 
    ltag: 'BASICLOGTAG', // Log tag. Some optional user supplied tag.
    ldtxt: 'LOGGING BASIC STUFF', // Log data text. Useful for marking points
    ldata: {
        'Abs': 54,
        'FullName': 'Utopia'
    }, // Log data. Actual log data, could be text | Object | Array | Error stack | E.t.c. 
    overridets: Date.now() // Each log is saved with a timestamp equal to the time the logit service recieved the request, you can pass your own timestamp (unix style) if you wish to override this
})

Level Wrappers

// 
const logit = require('logitlib')({writeKey:'aaa', apiURL: 'https://someurl.com'});
logit.error(1920, new Error('Owen mbape'), {});
logit.info(1920, {'somelogprop': 'somelogvalue'}, {});
logit.warning(1920, {'somethingtowarnabout':11}, {});

/*
The third argument to logit[level] type logs is an override object. Any prop in the object that matches the accepted logit rawLog payload will be overriden. E.g. if you pass { ldtxt: 'Something loggy' }, the ldtxt value will override any previously set ldtxt ones 
*/

Timeline logging

logitlib has a wrapper that makes it easy to create a log of an event. As you would if you were using console.timestart and console.timeend

const logit = require('logitlib')({writeKey:'aaa', apiURL: 'https://someurl.com'});
// Create an event journal for an event called serviceCharge
const eventJournal = logit.eventJournal('serviceCharge', {op: 1}, `${Date.now()}_UIDARG`);
// Event fetching_customer is started
eventJournal.note('fetching_customer');
// Event fetching_customer is stopped. Optional data about the fetching_customer event could be passed as the second argument
eventJournal.note('fetching_customer', {fullName: 'OberynMartel'});
eventJournal.note('fetching_customer_charge');
eventJournal.note('fetching_customer_charge', {charge: 39000});
//serviceCharge event is ended
eventJournal.end({});

A way to view the above event journal or timeline is:

ServiceCharge: Start
    fetching_customer: start
    fetching_customer: stop | {fullName: 'OberynMartel'}
    fetching_customer_charge: start
    fetching_customer_charge: stop | {charge: 39000}
ServiceCharge: Stop