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

resting-squirrel-es-logger

v1.0.3

Published

ElasticSearch logger for Resting Squirrel apps.

Downloads

4

Readme

resting-squirrel-es-logger

ElasticSearch logger for Resting Squirrel apps.

Requirements

  • Node.js >= 8
  • ElasticSearch 7

Installation

npm install resting-squirrel-es-logger --save

Usage

import rs from 'resting-squirrel'; // peer dependency
import logger from 'resting-squirrel-es-logger';

const app = rs({
	logger: logger(/* options */),
});

app.start();

Options

appName: string - Name of the application. Default: RS App
clearTemplate: boolean - Indicates if the ES template is deleted before the logger init. Default: false
getCustomData: (property: string, loggerData: ILoggerData) => any - Function to get the value of custom property. Default: null
indexTimeFormat: string - Time format from moment for the index suffix. Default: YYYY-MM-DD
node: string - ES node. Default: http://localhost:9200
onError: (error: any) => void - Function called if some error occurs. Default: null
onReady: () => void - Function called if the logger is ready. Default: null
template: Template - Template data. Default: { name: 'rs-es-logger', numberOfReplicas: 0, numberOfShards: 1, properties: {} }
transformBody: (property: string, value: any) => any - Function to transform property value before the save in the request body. Default: null
transformQuery: (property: string, value: any) => any - Function to transform property value before the save in the request query. Default: null

Template

name: string - Name of the template. Default: rs-es-logger
numberOfReplicas: number - Number of replicas. Default: 0
numberOfShards: number - Number of shards. Default: 1
properties: { [key: string]: any } - Custom template properties for custom data. Default: {}

Transforms

Data in body and query can be transformed.

import logger from 'resting-squirrel-es-logger';

logger({
	transformBody(property, value) {
		switch (property) {
			case 'password':
				return '********'; // We really don't want to have passwords in database
			case 'profile_picture': // The picture is in base64
				return `[file(${value?.length})]`; // We don't want to save large data to database
			default: 
				return value;
		}
	},
});

Custom data

Custom data can be indexed as well. It should be the data for further searches.

import logger from 'resting-squirrel-es-logger';

logger({
	template: {
		properties: {
			userId: {
				type: 'integer',
			},
		},
	},
	getCustomData(property, { headers }) {
		// Logger doesn't have access to the incoming request so we have to store the userId to the headers in auth middleware
		switch (property) {
			case 'userId':
				// After that we can access userId from headers and save it
				return headers?.userId || null;
			default: 
				return null;
		}
	},
});