fyipe-log-js

3.0.6657 • Public • Published

npm

Fyipe Application Logger

A fyipe application logger that can be used to send logs about your applications created on your fypie dashboard. It also provides a way to track errors in your application.

Installation

NPM Install

You can install to use in your project:

$ cd project
$ npm install fyipe-log-js

Basic Usage

In a Node.js Project

import { FyipeLogger } from 'fyipe-log-js';
 
// constructor
 
// set up tracking configurations
const options = {
    maxTimeline: 10,
};
const logger = new FyipeLogger(
    'API_URL', // https://fyipe.com/api
    'APPLICATION_LOG_ID',
    'APPLICATION_LOG_KEY',
    options // Optional Field
);
 
// Sending a string log to the server
const item = 'This is a simple log';
 
logger.log(item); // returns a promise
 
// Sending a JSON object log to the server
const item = {
    user: 'Test User',
    page: {
        title: 'Landing Page',
        loadTime: '6s',
    },
};
 
logger.log(item); // returns a promise
 
// Alternatively, Logs can be tagged with either a string or an array of strings
const item = 'This is a simple log';
const tags = ['server', 'script', 'dev'];
logger.log(item, tags);
 
const tag = 'testing';
logger.log(item, tag);

In the Browser

<script src="https://unpkg.com/fyipe-log-js"></script>
<script>
    function logError() {
        // constructor
        const logger = new FyipeLogger(
            'API_URL', // https://fyipe.com/api
            'APPLICATION_LOG_ID',
            'APPLICATION_LOG_KEY'
        );
 
        // Sending a string log to the server
        const item = 'This is a simple log';
 
        logger.log(item); // returns a promise
 
        // Alternatively, Logs can be tagged with either a string or an array of strings
        const item = 'This is a simple log';
        const tags = ['server', 'monitor'];
        logger.log(item, tags);
    }
</script>

Error Tracking APIs

import { FyipeTracker } from 'fyipe-log-js';
 
// constructor
 
// set up tracking configurations
const options = {
    maxTimeline: 10,
};
const tracker = new FyipeTracker(
    'API_URL', // https://fyipe.com/api
    'ERROR_TRACKER_ID',
    'ERROR_TRACKER_KEY',
    options // Optional Field
);
 
// capturing a timeline manually
tracker.addTimeline(
    'payment',
    { account: 'debit', amount: '6000.00', userId: 401 },
    'info'
);
 
// setting custom tags
tracker.setTag('category', 'Customer'); // a single tag
tracker.setTags([
    { key: 'type', value: 'notice' },
    { key: 'location', value: 'online' },
]); // an array of tags
 
// capturing error exception authomatically
NonExistingMethodCall(); // this is authomatically captured and sent to your fyipe dashboard
 
// capturing error exception manually
try {
    // your code logic
    NonExistingMethodCall();
} catch (error) {
    tracker.captureException(error);
}
 
// capturing error message
tracker.captureMessage('Message');

API Documentation

Main API to send logs to the server.

Author: HackerBay, Inc.

new FyipeLogger(apiUrl, applicationId, applicationKey)

Create a constructor from the class, which will be used to send logs to the server.

Kind: Constructor Returns: null

Param Type Description
apiUrl string The Server URL.
applicationId string The Application Log ID.
applicationKey string The Application Log Key.

new FyipeTracker(apiUrl, errorTrackerId, errorTrackerKey, options)

Create a constructor from the class, which will be used to track events and exceptions to be sent to the server.

Kind: Constructor Returns: null

Param Type Description
apiUrl string The Server URL.
errorTrackerId string The Error Tracker ID.
errorTrackerKey string The Error Tracker Key.
options object Set of configuration to be used for error tracking.

logger.log(log, tags)

Logs a request of type info to the server.

Kind: method of new FyipeLogger Returns: Promise - A promise response of a success or failure.

Param Type Description
log string | Object The content to the logged on the server.
tags string | Array The tag(s) to be attached to the logged item on the server.

logger.warning(log, tags)

Logs a request of type warning to the server.

Kind: method of new FyipeLogger Returns: Promise - A promise response of a success or failure.

Param Type Description
log string | Object The content to the logged on the server.
tags string | Array The tag(s) to be attached to the logged item on the server.

logger.error(log, tags)

Logs a request of type error to the server.

Kind: method of new FyipeLogger Returns: Promise - A promise response of a success or failure.

Param Type Description
log string | Object The content to the logged on the server.
tags string | Array The tag(s) to be attached to the logged item on the server.

tracker.setTag(key, value)

Set a tag for the error to be captured.

Kind: method of new FyipeTracker Returns: null

Param Type Description
key string The key for the tag.
value string The value for thr tag.

tracker.setTags([{key, value}])

Set an array of tags for the error to be captured.

Kind: method of new FyipeTracker Returns: null

Param Type Description
key string The key for the tag.
value string The value for the tag.

tracker.setFingerprint(fingerprint)

Set fingerprint for the next error to be captured.

Kind: method of new FyipeTracker Returns: null

Param Type Description
fingerprint string | array of strings The set of string used to group error messages on the server.

tracker.addTimeline(category, content, type)

Add a custom timeline element to the next error to be sent to the server

Kind: method of new FyipeTracker Returns: null

Param Type Description
category string The category of the timeline event.
content string | Object The content of the timeline event.
type string The type of timeline event.

tracker.captureMessage(message)

Capture a custom error message to be sent to the server

Kind: method of new FyipeTracker Returns: null

Param Type Description
message string The message to be sent to the server.

tracker.captureExceptio(error)

Capture a custom error object to be sent to the server

Kind: method of new FyipeTracker Returns: null

Param Type Description
error object The Error Object to be sent to the server.

Contribution

  • Clone repository
  • run npm i to install dependencies
  • run npm run test to run tests
  • run npm run build to build for production.

Package Sidebar

Install

npm i fyipe-log-js

Weekly Downloads

0

Version

3.0.6657

License

ISC

Unpacked Size

253 kB

Total Files

15

Last publish

Collaborators

  • hackerbayadmin