npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

wl-logs-elk

v1.0.2

Published

To make it easy for you to get started with GitLab, here's a list of recommended next steps.

Downloads

4

Readme

wl-logs-elk

wl-logs-elk is a simple and universal logging library with support for multiple transports. It provides configuration options to handle logs in the console, local file, or both.

Getting Started

This package is designed to work with a local ELK (Elasticsearch, Logstash, Kibana) setup. Follow the steps below to configure ELK on your system:

  1. Elasticsearch: Download Elasticsearch from https://www.elastic.co/downloads/ and start Elasticsearch by executing the command /bin/elasticsearch.bat.

  2. Kibana: Before starting Kibana, open the config/kibana.yml file and uncomment the line elasticsearch.hosts: ["http://localhost:9200"]. Start the Kibana service by executing the command /bin/kibana.bat.

  3. Logstash: Create a logstash.conf file at the root directory of your project with the following content:

    input{
        file{
            path=>"<../logs/service.log>"//your log file path 
            start_position=>"beginning"
        }
    }
    output{
        elasticsearch{
            hosts=>[
            "localhost:9200"
            ]
        }stdout{
            codec=>rubydebug
        }
    }

    For starting the logstash services execute command : logstash -f logstash.conf

  • [ ] Follow the instructions mentioned in this Reference video for additional guidance.

Add your files

cd existing_repo
git remote add origin https://gitlab.com/wavelabs/code-accelerators/apis/nodejs/log_management_elk.git
git branch -M main
git push -uf origin main

Usage

To use this package, import it and provide the necessary parameters as shown below:

const { LoggerService } = require('wl-logs-elk');
const logData = {
  LogLevel: 'error',       // possible values are [error/warn/info/debug/trace]
  LogFilePath: './logs/service.log',
  ElasticSearchHost: 'http://localhost:9200',
  KibanaIndxPrefix: 'myapp-',
  Service: 'local',
  HostName: 'localhost',
  LogStream : 'both'
};

const log = LoggerService(logData);
module.exports = { log };

Parameters: The following parameters can be provided in the logData object:

  • LogLevel: Set the log level for the entire application.
  • LogFilePath: Specify the log file path. This parameter is mandatory if LogStream is set to either file or both. If LogFilePath is not provided, an error will be thrown: "Error: LogFilePath should not be empty if LogStream is set to file or both."
  • ElasticSearchHost: The URL where Elasticsearch services are running.
  • KibanaIndxPrefix: Preferred index prefix to aid in discovering indexes in Kibana.
  • Service: Service name.
  • HostName: Application host name.
  • LogStream: Possible values are file, console, or both.

Logging Examples

To log messages, import the log object from the service file and use it as follows:

const { log } = require('./src/app/service');
const logData = {
  sessionId: '3232323',
  data: { otp: 100 },
  APIId: 'API002',
  api: '/api/validate'
};
log.info('service api', logData);
log.error('error message');
log.warn('warn message');
log.debug('debug message');
log.trace('debug message');

Feel free to customize the log data according to your needs.

Log Levels:

  • error
  • warn
  • info
  • debug
  • trace