TanmoySG / logsmith-monitor

A centralized log monitoring server
4 stars 0 forks source link

[Feature] NodeJS Helper Library #39

Closed TanmoySG closed 2 years ago

TanmoySG commented 2 years ago

NodeJS Helper Library/Class for logsmith monitor. May publish a JS counterpart of logsmith - logsmithJS, as a logging library with support for monitor.

[Checkpoints]

[Additional Details]

TanmoySG commented 2 years ago

Using this Guide - https://www.digitalocean.com/community/tutorials/how-to-create-a-node-js-module

For Coloring the terminal logs using - https://www.npmjs.com/package/chalk

Some guide on Classes in JS - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes

TanmoySG commented 2 years ago

"git - How to use actions/checkout@master to get sources into specified folder? - Stack Overflow" https://stackoverflow.com/questions/57914734/how-to-use-actions-checkoutmaster-to-get-sources-into-specified-folder

Can use this to checkout only the helper library and Publish it as a GH Package.

TanmoySG commented 2 years ago

How to Publish to NPM Registry

Login to npm

npm adduser

A prompt comes up, fill the details.

npm publish

Voila!

TanmoySG commented 2 years ago

How to go ahead with NodeJS Helper Library Publishing?

TanmoySG commented 2 years ago

[Publishing to GH Registry] https://gist.github.com/silentHoo/8402d470ef48ef8979b8ecd3e5f206e3

TanmoySG commented 2 years ago

Will publish to NPM Registry - less steps to follow for end user.

TanmoySG commented 2 years ago

https://www.npmjs.com/package/log

TanmoySG commented 2 years ago

Templating in JS

Using string-template for Templating. Link

Usage

Installing string-template

npm i string-template

Defining Templates can be done by putting the variable/placeholder name within { }

const template = "{level} : {log}"

Formatting the templates

import format from 'string-template';

const template = "[{level}] {body}"
log() {
        const logStatement = format(
            template,
             { 
                level:"test",
                body:  "testval"
              }
         )
        return logLevels.INFO(logStatement);
    }

Examples

Refer to these examples

TanmoySG commented 2 years ago

"Doing a cleanup action just before Node.js exits - Stack Overflow" https://stackoverflow.com/questions/14031763/doing-a-cleanup-action-just-before-node-js-exits

Save logs in file on exit only. Read Logs and write logs to Program Variables and not to file.

TanmoySG commented 2 years ago

https://headlessui.dev/react/tabs

TanmoySG commented 2 years ago

Minimal Monitor Configuration

This is the minimum config the user needs to set for monitor, rest is handled by the lib. if not provided.

{
       MONITOR: {
            port: "8080",
            server: "localhost",
            publisher: {
                publisher: "test"
            },
            context: {
                context: "testcon"
            }
        }
    }
}
TanmoySG commented 2 years ago

If exists Fallback

While publishing log

TanmoySG commented 2 years ago

Might Help - https://www.youtube.com/watch?v=cuEtnrL9-H0&ab_channel=WebDevSimplified

TanmoySG commented 2 years ago
const EndpointConfigurations = {
    Publisher: {
        method : "POST",
        header : "GET"
    },
    Context : {
        new: "POST",
        existing : "GET"
    },
    Log: {
        new: "POST"
    }
}
TanmoySG commented 2 years ago

https://stackabuse.com/making-http-requests-in-node-js-with-node-fetch/ Might Help

TanmoySG commented 2 years ago

Useful Resources

TanmoySG commented 2 years ago

Published!!!

https://www.npmjs.com/package/logsmithjs