Git Product home page Git Product logo

simplelogger's Introduction

SimpleLogger

A simple javascript logger class that sends message blobs to yours console and to a configured backend

1. Importing the logger

import SimpleLogger from '[path to simpleLogger.js]';

2. Instantiating a SimpleLogger object

A SimpleLogger object needs a httpEndpoint and noOfCollectedMessages.

Assumptions:

  • The server that receives the logger message objects accepts object blobs. If you are using strong typechecking, make sure to cast your messages in the required type before sending them to the logger

  • Your logging requirements ask for an optimized data transfer, therefore a use case where you'd need to send multiple log messages at once is possible. Please make sure the noOfCollectedMessages is instanciated

let myLogger = new SimpleLogger({
    httpEndpoint: 'https://postman-echo.com/post',
    httpHeaderOptions: {
        'Content-Type': 'application/json'
    },
    requestMethod: 'POST',
    noOfCollectedMessages: 3
});

3. Sending message objects to the SimpleLogger's message que.

Assuming your configuration objects from the SimpleLogger constructer is valid.

  • message - is a javascript object
  • localDisplay - is a flag that indicated if the message should also be logged in the clinet console. by default it is true
pushToQue(message, localDisplay = true)

Example

// adding message objects to SimpleLogger's internal messageQue
for (let i = 0; i < 7; i++) {

    myLogger.pushToQue({foo: i + '.bar'}, true); 
    // this will fire two times, since noOfCollectedMessages is equat to 3

} 

4. Sending message objects to the your endpoint.

This function will not push the message into the internal message que, but straight to your http endpoint. It has the same parameters as above. The endpoint and transport related information is taken from the configuration you instantiated your logger (see section 2)

  • message - is a javascript object
  • localDisplay - is a flag that indicated if the message should also be logged in the clinet console. by default it is true
pushToEndpoint(message, localDisplay = true)

Example

// posting a unique message
myLogger.pushToEndpoint({
    foo: 'unique.bar'
}, true)

simplelogger's People

Contributors

cristian-d-bara avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.